Is it possible to get client machine Location without the IP address? I tried different codes to get the client machine IP address, but none of them is giving the correct IP, either it give 127.0.0.1 Or 10.0.0.3.
What I have tried:
I tried the below two methods
1)
private string GetUserIP()
{
string ipList = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ipList))
{
return ipList.Split(',')[0];
}
return Request.ServerVariables["REMOTE_ADDR"];
}
This will give 127.0.0.1
2)
public static string getExternalIp()
{
try
{
string externalIP;
externalIP = (new WebClient()).DownloadString("http://checkip.dyndns.org/");
externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"))
.Matches(externalIP)[0].ToString();
return externalIP;
}
catch { return null; }
}
This will get the correct IP, but it takes long time to get the Out put, Is there any code which will get the IP very fast.