External IP / Router's IP / WAN IP  
Author Message
Ting.Choo.Chiaw





PostPosted: .NET Framework Networking and Communication, External IP / Router's IP / WAN IP Top

There are many ways of detecting external IP of router. One of the easiest if using "web services".
However, this method has risk of using because the web service may change anytime and therefore this method will no more applicable.
I will talk about how to request external IP from "external DNS" in other time. Today i talk about the easiest way first.
System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(" http://www.hide-link.com/ 
ismyip.org/");

request.UserAgent = "User-Agent: Mozilla/4.0 (compatible; MSIE
6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
System.Net.HttpWebResponse response =
	(System.Net.HttpWebResponse)request.GetResponse();

string myExternalIP = string.Empty;

using (System.IO.StreamReader reader = new
	StreamReader(response.GetResponseStream()))
{

	myExternalIP = reader.ReadToEnd();
	reader.Close();
}

response.Close();


.NET Development35  
 
 
Aymaneez





PostPosted: .NET Framework Networking and Communication, External IP / Router's IP / WAN IP Top

Hi

this is more easy now:

string ip = new WebClient().DownloadString(http://www.whatismyip.com/automation/n09230945.asp);