Get public/external IP address

Use the following code to get your wan/external/public ip address using http://dyndns.org site.

try
{
	System.Net.WebClient wc = new System.Net.WebClient();
	String s = wc.DownloadString("http://checkip.dyndns.org");
	s = (
		new System.Text.RegularExpressions.Regex(
			@"bd{1,3}.d{1,3}.d{1,3}.d{1,3}b")).
			Match(s).Value;
	wc.Dispose();
	Console.WriteLine(s);
}
catch (Exception)
{
	//...
}
Categories: C# Tags: , , , , ,
%d bloggers like this: