External IP in C #

What is the easiest way to get my external IP address in C #?

+4
source share
2 answers

There is no built-in way to do this within the framework, because it is difficult to determine what an external / public IP address is. This, of course, assumes that your IP address belongs to NAT behind some gateways.

One way would be to clean the site, for example http://www.whatismyip.org/ , using WebClient .

System.Net.WebClient client = new System.Net.WebClient(); string ip = client.DownloadString( "http://www.whatismyip.org" ); Console.Out.WriteLine( ip ); 
+7
source
 public static string GetExternalIP() { using (var wc = new System.Net.WebClient()) return wc.DownloadString("http://whatismyip.org"); } 
+3
source

Source: https://habr.com/ru/post/1302562/


All Articles