asp下比较全面的获取IP地址的代码
程序员文章站
2022-05-18 11:35:57
最简单的用以下语句: ip=request.servervariables("remote_addr") response.write(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)
%>
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)
%>
下一篇: 2018Android开发大公司面试经验