Refresh URL

I want to find the user's public IP address. To do this I am using a hidden WebBrowser control that navigates to http://www.whatismyip.com/. I then use a Regular Expression to get the IP. Every 10 minutes I want to check if the IP has changed.

Currently, I am using WebBrowserControl1.Refresh() to get the new IP but it does not work - I always get the IP that was found when the program first started. If I restart the program I get the new IP address.

How do I get the new content of the page rather than the old content



Answer this question

Refresh URL

  • Binju Paul

    using System;

    using System.Net;

    using System.Web;

    using System.IO;

    using System.Text;

    using System.Text.RegularExpressions;

     

    namespace GetExternalIP

    {

    class ExternalIP

    {

    public static string GetExternalIP()

    {

    const string IP_URL = "http://www.ipchicken.com/";

    string strHTML, strIP;

    try

    {

    WebRequest objWebReq = WebRequest.Create(IP_URL);

    WebResponse objWebResp = objWebReq.GetResponse();

    Stream streamResp = objWebResp.GetResponseStream();

    StreamReader srResp = new StreamReader(streamResp,

    Encoding.UTF8);

    strHTML = srResp.ReadToEnd();

    Regex regexIP = new Regex(

    @"\b\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\b");

    strIP = regexIP.Match(strHTML).Value;

    return strIP;

    }

    catch

    {

    return "Problem Getting IP Address";

    }

    }

    }

    }



  • mookiebud

    Thanks...That is MUCH better than my little WebBrowser Hack...
  • Refresh URL