'一般使用取得IP的方法,

'取得ClientIP

ClientIP = Request.ServerVariables("REMOTE_ADDR").ToString()

'對於使用代理伺服器的IP取得方法,

'判斷是否使用代理伺服器,如無使用則會為空

Request.ServerVariables["HTTP_VIA"].ToString()

'如有使用代理伺服器則可用以下方法取得真實IP

Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString()

完整取得ClientIP的方法

Dim strIPAddr As String

Dim id As Integer

Dim ip As String

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

 

'使用以下方法提取出IP

ip = Mid(strIPAddr, 1, 30).Trim.ToString

創作者介紹

蛤什麼蛤?

joysdw12 發表在 痞客邦 PIXNET 留言(0) 人氣()