新安数据

您的当前位置:网站首页 » 帮助中心» CDN相关

使用CDN的ASP网站如何取到用户真实IP程序

来源:新安数据类型:帮助文件 更新:2013-7-25 点击:29680

写了下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

上一篇文章:什么是CDN?下一篇文章:使用了CDN后取真实IP的PHP代码

我们很乐意帮助您!请联系在线客服或致电我们。7×24小时客服热线: 0551-62886237