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

2018-09-06 10:31

阅读:735

  最简单的用以下语句:

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

复制代码 代码如下:
<%PrivateFunctiongetIP()
DimstrIPAddr
IfRequest.ServerVariables(HTTP_X_FORWARDED_FOR)=ORInStr(Request.ServerVariables(HTTP_X_FORWARDED_FOR),unknown)>0Then
strIPAddr=Request.ServerVariables(REMOTE_ADDR)
ElseIfInStr(Request.ServerVariables(HTTP_X_FORWARDED_FOR),,)>0Then
strIPAddr=Mid(Request.ServerVariables(HTTP_X_FORWARDED_FOR),1,InStr(Request.ServerVariables(HTTP_X_FORWARDED_FOR),,)-1)
ElseIfInStr(Request.ServerVariables(HTTP_X_FORWARDED_FOR),;)>0Then
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)
EndIf
getIP=Trim(Mid(strIPAddr,1,30))
EndFunction
ip=getIP()
response.write(ip)
%>


评论


亲,登录后才可以留言!