Before anything I know this question is duplicated but let me tell about my prob
As This Link demonstrated the Request.UserHostAddress
only captures the IP address of the proxy server or router
for this reason I have used this code to return users IP Address :
string ip = String.IsNullOrEmpty(Request.ServerVariables["HTTP_X_FORWARDED_FOR"]) ? Request.ServerVariables["REMOTE_ADDR"] : Request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(',')[0];
but it always return 172.30.1.1
when I connect with my PC,
in the other side my Phone is connected to Telecommunication 3G network
when I connected by phone that returns 172.30.1.1
again.
I also use this code:
public static string GetIP4Address()
{
string IP4Address = String.Empty;
foreach (IPAddress IPA in Dns.GetHostAddresses(HttpContext.Current.Request.UserHostAddress))
{
if (IPA.AddressFamily.ToString() == "InterNetwork")
{
IP4Address = IPA.ToString();
break;
}
}
if (IP4Address != String.Empty)
{
return IP4Address;
}
foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName()))
{
if (IPA.AddressFamily.ToString() == "InterNetwork")
{
IP4Address = IPA.ToString();
break;
}
}
return IP4Address;
}
but results are same.
so How can I return the real IP address of users?
Thanks in advance.