If you computers are sitting behind a router/firewall, then running Ipconfig would not give you the external IP address. One can use http://www.whatsmyip.org/ for ad-hoc queries, but if you want to automate the checks you might want something simpler and easier to parse. The followings are the options I found.
- http://automation.whatismyip.com/n09230945.asp
This is the page they specifically provided for automation and the good thing is you do not have to worry about parsing. - http://checkip.dyndns.com
The return that they give back to you is short and easy to work with. - http://www.domaintools.com/research/my-ip/myip.xml
The most comprehensive one, it gives you all the network related info in XML format.
The c# code to find out your external IP:
public string GetPublicIP() { String direction = ""; WebRequest request = WebRequest.Create("http://checkip.dyndns.org/"); using (WebResponse response = request.GetResponse()) using (StreamReader stream = new StreamReader(response.GetResponseStream())) { direction = stream.ReadToEnd(); } //Search for the ip in the html int first = direction.IndexOf("Address: ") + 9; int last = direction.LastIndexOf("</body>"); direction = direction.Substring(first, last - first); return direction; } |