做了CDN加速的ASP网站获取用户真实IP程序
程序员文章站
2022-05-18 11:36:33
复制代码 代码如下: function checkip(checkstring)'用正则判断ip是否合法 dim re1 set re1=new regexp re1.pa...
复制代码 代码如下:
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