Reputation: 931
I need get the local machine ip address of my website visited users for that i used below code
string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ipAddress))
{
string[] addresses = ipAddress.Split(',');
if (addresses.Length != 0)
{
stradd = addresses[0];
}
else
{
stradd = ipAddress;
}
}
else
{
stradd = Request.ServerVariables["REMOTE_ADDR"].ToString();
}
hostName = Dns.GetHostByAddress(stradd).HostName;
this is giving the ip address of the service provider & name of the service provider but i don't want this i wanted user device(local) ip address, is it possible to get local ip address? please help me.
Upvotes: 0
Views: 703
Reputation: 390
The local IP is just that (local) it will never leave the local router, you will need to use some sort of locally executed code to send it to the server.
Upvotes: 0
Reputation: 943217
No. You can't get the private IP address of a machine hidden behind NAT.
The router relays the request transparently.
Upvotes: 1