The ASPX vb.net gets the real IP function as follows:
Copy Code code as follows:
<script runat= "Server" >
Public Function checkip (ByVal IP as String) as Boolean
Dim Pat as String = "^[0-9]{1,3}." [0-9] {1,3}. [0-9] {1,3}. [0-9] {1,3}$ "
Dim reg as Regex = New Regex (PAT)
If IP = "" Then
Checkip = False
Exit Function
End If
Checkip = Reg. IsMatch (IP)
End Function
Public Function get_cli_ip () as String
If Not (System.Web.HttpContext.Current.Request.ServerVariables ("http_client_ip") are nothing) and Checkip ( System.Web.HttpContext.Current.Request.ServerVariables ("http_client_ip")) = True) Then
GET_CLI_IP = System.Web.HttpContext.Current.Request.ServerVariables ("Http_client_ip")
Exit Function
ElseIf Not (System.Web.HttpContext.Current.Request.ServerVariables ("http_x_forwarded_for") are nothing) Then
Dim IPs () as String = Split (System.Web.HttpContext.Current.Request.ServerVariables ("Http_x_forwarded_for"), ",")
For i as Integer = 0 to IPs. Length-1
If Checkip (Trim (IPs (i)) = True Then
GET_CLI_IP = Trim (IPs (i))
Exit Function
End If
Next
End If
GET_CLI_IP = System.Web.HttpContext.Current.Request.ServerVariables ("REMOTE_ADDR")
End Function
</script>
Complete test page:
Copy Code code as follows:
<%@ Page language= "VB" autoeventwireup= "false" codefile= "Default.aspx.vb" inherits= "_default"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<script runat= "Server" >
Public Function checkip (ByVal IP as String) as Boolean
Dim Pat as String = "^[0-9]{1,3}." [0-9] {1,3}. [0-9] {1,3}. [0-9] {1,3}$ "
Dim reg as Regex = New Regex (PAT)
If IP = "" Then
Checkip = False
Exit Function
End If
Checkip = Reg. IsMatch (IP)
End Function
Public Function get_cli_ip () as String
If Not (System.Web.HttpContext.Current.Request.ServerVariables ("http_client_ip") are nothing) and Checkip ( System.Web.HttpContext.Current.Request.ServerVariables ("http_client_ip")) = True) Then
GET_CLI_IP = System.Web.HttpContext.Current.Request.ServerVariables ("Http_client_ip")
Exit Function
ElseIf Not (System.Web.HttpContext.Current.Request.ServerVariables ("http_x_forwarded_for") are nothing) Then
Dim IPs () as String = Split (System.Web.HttpContext.Current.Request.ServerVariables ("Http_x_forwarded_for"), ",")
For i as Integer = 0 to IPs. Length-1
If Checkip (Trim (IPs (i)) = True Then
GET_CLI_IP = Trim (IPs (i))
Exit Function
End If
Next
End If
GET_CLI_IP = System.Web.HttpContext.Current.Request.ServerVariables ("REMOTE_ADDR")
End Function
</script>
<title>untitled page</title>
<body>
<%
Dim client_ip as String = Get_cli_ip ()
System.Web.HttpContext.Current.Response.Write (CLIENT_IP)
%>
</body>