发新话题
打印

[转载]获得IP和封锁IP的ASP代码

[转载]获得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



其实可以自己结合起来玩玩。赫赫。没有什么实际用处。学习学习而已。
曾几何时,有人对我说:装B遭雷劈。我说:去你妈的。于是,这个人又对我说:如果再说脏话,上帝会惩罚你的。我说:我操上帝。结论:彪悍的人生不需要上帝。

TOP

发新话题