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)
%>

查看 ASP ip的相关文章

转载本站原创文章请注明:文章转自 挨踢路,链接: https://itlu.org/articles/1835.html

已有 3 条评论

  1. 我的天啊。你可是真够专业的,这么复杂的代码呀文字啊,你都写的这么清楚的,真佩服你。

  2. 还真有那么多人还在研究Asp呀。

    1. 自己已经很少看代码了,只是昨天更好朋友问到而已,我就找了下资料,顺便记录了下来。

添加新评论

您好,#请填信息#修改