Donate

How To Show External IP Address Using C# And WebClient

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.

//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));

Comments

  1. Hi,

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

    :)

    ReplyDelete

Post a Comment

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input