cdn或反向代理后获取用户真实IP的函数代码Asp版
发布时间:2014-07-20 编辑:jiaochengji.com
asp获取cdn或反向代理后的用户真实IP的代码,无代理、一级或多级代理的情况均可以正常获取,有需要的朋友,可以参考下。
asp函数代码。
复制代码 代码示例:
<%
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
'-------------------------------------------------------------
'取真实IP函数,先 HTTP_CLIENT_IP 再 HTTP_X_FORWARDED_FOR 再 REMOTE_ADDR
'-------------------------------------------------------------
function get_cli_ip()
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
%>
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
'-------------------------------------------------------------
'取真实IP函数,先 HTTP_CLIENT_IP 再 HTTP_X_FORWARDED_FOR 再 REMOTE_ADDR
'-------------------------------------------------------------
function get_cli_ip()
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或反向代理后获取用户真实IP的函数代码Asp版
cdn或反向代理后获取用户真实IP的函数代码PHP版
深入解析PHP获取客户端IP的方法
php 获取网站地址的函数代码
使用PHP来获取客户端和服务端IP
php获取客户端的真实IP的方法介绍
php怎么处理高并发问题?
squid多级反向代理下获取客户端真实IP地址
php函数获取在线ip与客户端ip
php获取ip的多种方法
下一篇:asp 删除数据库记录入门教程
[关闭]