0

Possible Duplicate:
Get local ip address c#

Currently I am using following code for getting the ip addrress of each machine who have logged in my website. It is working fine if my website is in my intranet server.But if the same code is deployed at customer server and if I am accessing the site from my place using to customer application URL like (http://123.23.45.89/MyProd/App.htm), it is updating the ip addreress of my server address,not my local machine IP.

string IP4Address = String.Empty;

foreach (IPAddress IPA in Dns.GetHostAddresses(Request.ServerVariables["REMOTE_ADDR"].ToString())))
{
  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;

If there is any other way to find the ip address for individual PC.(like finding the local ip addess from any machine through out internet Network)

Community
  • 1
  • 1

1 Answers1

2

As far as I know, all the connections from a LAN network towards and external server have the WAN Ip of the network (normally the router's). :(

SilentDoc
  • 357
  • 2
  • 8
  • yes, if NAT is in place (which it probably should be) – paul Jan 28 '13 at 12:02
  • So is there any other way to handle this scenario??? – Arun Verma Jan 28 '13 at 12:05
  • None that I can think of, as paul points out the router is the one handling this conversion at TCP/IP layer, so I see little margin there. However, as this question has been marked as duplicate, I would suggest searching for similar questions at StackOverflow to see if other users came out with a solution, but I don't see a way to bypass the router translation in here :( – SilentDoc Feb 01 '13 at 08:14