Gokul's Blog

Get My IP Simulation

Leave a comment



Code following Shortly.


Code to get the IP from Webpage to a Console App

   // Use a web page that displays the IP of the request.  
   WebRequest myRequest = WebRequest.Create("http://Myurl");

   // Send request, get response, and parse out the IP address on the page.
   using(WebResponse res = myRequest.GetResponse())
    using(Stream s = res.GetResponseStream())
    using(StreamReader sr = new StreamReader(s, Encoding.UTF8))
     string html = sr.ReadToEnd();
     Regex regex = new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b");
     string ipString = regex.Match(html).Value;
     Console.WriteLine("Public IP: "+ipString);
  catch(Exception ex)
   Console.WriteLine("Error getting IP Address:\n"+ex.Message);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s