Asp获取真实IP地址

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地址)