做了CDN加速的ASP网站获取用户真实IP程序
更新时间:2010年11月03日 11:40:31 作者:
写了下asp取真实IP的代码,搭环境测试无代理、一级或多级代理的情况,可以正常获取
复制代码 代码如下:
function checkip(checkstring)'用正则判断IP是否合法
dim re1
set re1=new RegExp
re1.pattern="^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"
re1.global=false
re1.Ignorecase=false
checkip=re1.test(checkstring)
set re1=nothing
end function
复制代码 代码如下:
function get_cli_ip()'取真实IP函数,先 HTTP_CLIENT_IP 再 HTTP_X_FORWARDED_FOR 再 REMOTE_ADDR
dim client_ip
if checkip(Request.ServerVariables("HTTP_CLIENT_IP"))=true then
get_cli_ip = checkip(Request.ServerVariables("HTTP_CLIENT_IP"))
else
MyArray = split(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),",")
if ubound(MyArray)>=0 then
client_ip = trim(MyArray(0))
if checkip(client_ip)=true then
get_cli_ip = client_ip
exit function
end if
end if
get_cli_ip = Request.ServerVariables("REMOTE_ADDR")
end if
end function
相关文章
asp之GetArray提取链接地址,以$Array$分隔的代码
asp之GetArray提取链接地址,以$Array$分隔的代码...2007-09-09
ASP中用select case代替其他语言中的switch case, default用case else
这篇文章主要介绍了ASP中用select case代替其他语言中的switch case, default用case else ,需要的朋友可以参考下2015-11-11
在asp中使用js的encodeURIComponent方法
encodeURIComponent 方法返回一个已编码的 URI。如果您将编码结果传递给 decodeURIComponent,那么将返回初始的字符串2012-03-03


最新评论