Thursday, June 23, 2011

Show External IP address using C#

I experimented a snippet to get my ISP provided IP address using whatismyip. Using tutorials or code snippets from links, the web request just returned a 404 error. After reading the whatismyip API again,they have changed their automation URL. Below is the code snippet.

Code:
  //previous URL present on most tutorials which is not working  
  //string whatIsMyIp = "http://www.whatismyip.com/automation/n09230945.asp";   
  //updated URL from whatismyip API  
  string whatIsMyIp = "http://automation.whatismyip.com/n09230945.asp";  
  WebClient wc = new WebClient();  
  UTF8Encoding utf8 = new UTF8Encoding();  
  string requestHtml = "";  
  requestHtml = utf8.GetString(wc.DownloadData(whatIsMyIp));

4 comments:

  1. Pretty great post. I simply stumbled upon your blog and wanted to say that I've really loved browsing your blog posts.
    After all I'll be subscribing to your rss feed and I hope you
    write again soon!

    my homepage: Hopfen vorbei zu diesen Kerlen (http://Www.Ladynail.Homepage.eu/guestbook.html)

    ReplyDelete
  2. Hi,

    Thank you for such kind words. It gives me the motivation to write more articles provide education to the IT community.

    :)

    ReplyDelete