岁月联盟 - 技术社区 - BBS.SYUE.COM's Archiver

猪猪 发表于 2007-2-11 14:51

获得IP和封锁IP的ASP代码

信息来源:Hoky Security Team [特络纳]

得到真实IP

得到IP地址的方法是<%=Request.ServerVariables("REMOTE_ADDR")%>,如果客户使用的代理服务器,这样就得到了代理服务器的IP,下面是得到真实IP的代码:

function GetIp()
dim realip,proxy
realip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
proxy = Request.ServerVariables("REMOTE_ADDR")
if realip = "" then
  GetIp = proxy
else
  GetIp = realip
end if
end function




限制某段IP地址
限制某段IP地址访问网页的一个列子:

function IP2Num(sip)
dim str1,str2,str3,str4
dim num
IP2Num=0
if isnumeric(left(sip,2)) then
  str1=left(sip,instr(sip,".")-1)
  sip=mid(sip,instr(sip,".")+1)
  str2=left(sip,instr(sip,".")-1)
  sip=mid(sip,instr(sip,".")+1)
  str3=left(sip,instr(sip,".")-1)
  str4=mid(sip,instr(sip,".")+1)
  num=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)-1
  IP2Num = num
end if
end function

userIPnum = IP2Num(Request.ServerVariables("REMOTE_ADDR"))

if userIPnum > IP2Num("192.168.0.0") and userIPnum < IP2Num("192.168.0.255") then
response.write ("<center>您的IP被禁止</center>")
response.end
end if



其实可以自己结合起来玩玩。赫赫。没有什么实际用处。学习学习而已。

♂╰王孒ゝ 发表于 2007-4-13 09:57

嘿嘿。。。能不能隐藏自己的IP的哦

xlight 发表于 2007-4-13 22:13

呵呵

冰的原点 发表于 2007-6-17 06:02

现在好多ASP程序上都用到了这段代码!

我就遇到过一些防注入程序,一旦你提交非法数据就记录你的IP,还弹框,呵呵,蛮吓人的!

页: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2009 Comsenz Inc.