Is it possible to determine your IP through a C # program? Preferably local IP and external. And, if it is possible to find out through a router, how? Can you tell in which direction to dig or sample code to show me?

  • one
    And what is the "external" address? (By the way, from the primer. The IP address does not belong to the host, but only to (sub-) interfaces) - alexlz

2 answers 2

Maybe:

foreach (System.Net.IPAddress ip in System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList) { Console.WriteLine(ip.ToString()); } 

These are local addresses.

  • Thank you) - handbat0

No one except the router knows the external IP, so the only way to find it out is to ask your IP from someone behind the router, for example, http://www.myip.ru/ru-RU/index.php