inicio mail me! sindicaci;ón

How does ASP get a client to carry true IP address

Want to obtain the true IP address that the client carries through acting server, be about to use Request.ServerVariables(”HTTP_X_FORWARDED_FOR” ) to read take. Want watchful job nevertheless, not be every representative server can read the true IP that takes client end with Request.ServerVariables(”HTTP_X_FORWARDED_FOR” ) , some read those who take to remain the IP of acting server with this method. Returning those who have attention of a bit need is: If client end did not pass acting server to visit, so the cost that takes with Request.ServerVariables (”HTTP_X_FORWARDED_FOR” ) will be empty. Accordingly, if want to use this method in the program, can handle so:

. . . . . .

Userip = Request.ServerVariables(”HTTP_X_FORWARDED_FOR” )

If Userip = “” Then Userip = Request.ServerVariables(”REMOTE_ADDR” )

. . . . . .   

Namely: If client end passes acting server, take the cost of HTTP_X_FORWARDED_FOR, if did not pass acting server, take the cost of REMOTE_ADDR.   

‘ general function: If cannot take a client to carry true IP, with respect to the acting IP that can take a client to carry

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

Bookmark:Digg Del.icio.us Reddit

Leave a Comment