得到客户端IP的code

[ 2004-09-08 18:27:52 | Author: zhenhua ]
Font Size: Large | Medium | Small
得到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

Comments Feed Comments Feed: http://www.zhenhua.org/feed.asp?q=comment&id=138
UTF-8 Encoding Trackback URL: http://www.zhenhua.org/trackback.asp?id=138

There is no comment on this article.

If you feel this site you find this information helpful, please click on the donation, which is voluntary,Thank you.
Post Comment
Smilies
[arrow] [biggrin] [confused] [cool]
[cry] [eek] [evil] [exclaim]
[frown] [idea] [lol] [mad]
[mrgreen] [neutral] [question] [razz]
[redface] [rolleyes] [sad] [smile]
[surprised] [twisted] [wink]
Enable UBB Codes
Auto Convert URL
Show Smilies
Hidden Comment
Username:   Password:   Register Now?
Security Code * Please Enter the Security Code