'一般使用取得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

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 joysdw12 的頭像
    joysdw12

    蛤什麼蛤?

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