1

I don't know if I'm just not searching using the right keywords, I want to be able to find the IP address of my local computer that was assigned by my router.

I was using:

IPHostEntry host;
host = Dns.GetHostEntry(Dns.GetHostName());

foreach(IPAddress ip in host.AddressList)
{
   if(ip.addressfamily.tostring() == "InterNetwork")
   {
      return ip;
   }
}

The problem is I have multiple InterNetwork ip addresses because I use virtual services, so I need to be able to identify which one was assigned by my router.

David Torrey
  • 1,335
  • 3
  • 20
  • 43

1 Answers1

0

How about loopback?

if (IPAddress.IsLoopback(ip)) return ip; //localhost

Or try pinging the local machine

Ping pingSender = new Ping ();
IPAddress address = IPAddress.Loopback;
PingReply reply = pingSender.Send (address);
if (reply.Status == IPStatus.Success){..}

also this might help you

Showing The External IP-Address In C#

tatigo
  • 2,174
  • 1
  • 26
  • 32
  • this still doesnt single out the ip address that was assigned by the router – David Torrey Apr 27 '14 at 05:11
  • I'm not sure what is the question then, do you want to know the IP address of your router that faces the Internet? in most cases the first ip in the collection of ips is the external interface of your router – tatigo Apr 28 '14 at 01:16
  • I think I found a solution, I'll post it up as the answer once I do a couple tests and see if it's legit. Will be using http://stackoverflow.com/questions/4553453/how-to-get-ip-address-in-c for the solution – David Torrey Apr 28 '14 at 15:15