/** // <Summary>
/// Obtain the real IP address of the client. If a proxy exists, the first non-Intranet address is used.
/// </Summary>
Public static string IPAddress
{
Get
{
String result = String. Empty;
Result = HttpContext. Current. Request. ServerVariables ["HTTP_X_FORWARDED_FOR"];
If (result! = Null & result! = String. Empty)
{
// A proxy may exist.
If (result. IndexOf (".") =-1) // No "." is definitely not in IPv4 format.
Result = null;
Else
{
If (result. IndexOf (",")! =-1)
{
// There are ",", and multiple proxies are estimated. Obtain the first IP address that is not an intranet IP address.
Result = result. Replace ("", ""). Replace ("'","");
String [] temparyip = result. Split (",;". ToCharArray ());
For (int I = 0; I <temparyip. Length; I ++)
{
If (IsIPAddress (temparyip [I])
& Temparyip [I]. Substring (0, 3 )! = "10 ."
& Temparyip [I]. Substring (0, 7 )! = "192.168"
& Temparyip [I]. Substring (0, 7 )! = "172.16 .")
{
Return temparyip [I]; // locate an address that is not an intranet address
}
}
}
Else if (IsIPAddress (result) // The proxy is in the IP Format
Return result;
Else
Result = null; // the content in the proxy is not an IP address and the IP address is used.
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.