当前位置:首页 > ASP教程 > 应用技巧

asp下比较全面的获取IP地址的代码

最简单的用以下语句:

ip=request.servervariables("remote_addr") 
response.write(ip)
但这种方法对代理服务器上网的就不准了,故比较全面的是用下面的方法:

复制代码 代码如下:

<%private function getip()  
dim stripaddr  
if request.servervariables("http_x_forwarded_for") = "" or instr(request.servervariables("http_x_forwarded_for"), "unknown") > 0 then  
stripaddr = request.servervariables("remote_addr")  
elseif instr(request.servervariables("http_x_forwarded_for"), ",") > 0 then  
stripaddr = mid(request.servervariables("http_x_forwarded_for"), 1, instr(request.servervariables("http_x_forwarded_for"), ",")-1)  
elseif instr(request.servervariables("http_x_forwarded_for"), ";") > 0 then  
stripaddr = mid(request.servervariables("http_x_forwarded_for"), 1, instr(request.servervariables("http_x_forwarded_for"), ";")-1)  
else  
stripaddr = request.servervariables("http_x_forwarded_for")  
end if  
getip = trim(mid(stripaddr, 1, 30))  
end function 
ip=getip() 
response.write(ip) 
%>

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!