萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> asp編程 >> 用通ASP直接獲取用戶真實IP地址

用通ASP直接獲取用戶真實IP地址

   通用FUNCTION,如果不能取真實IP,就會取代理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

copyright © 萬盛學電腦網 all rights reserved