Netgear router monitor

Feeling bored and looking for some fun, I wrote a Netgear router monitor program. This is what programmers do.  I was interested in seeing what websites were accessed through the router at my home.  While there is a log available via the router, the buffer in a router are notoriously small and data that are only a few minutes old are lost.  This tool fixes that by polling the router every few seconds.  The tool looks for router that is a model WGR614v6, but other Netgear routers may work.  For other routers, I would expect a change to the code to parse the output.

The executable (.NET) is here, and the source code is here (C# Windows Form application).  You have to be able to provide a login ID, password, and domain for your router for it to work.

The only difficult part was understanding how to use the network credentials for specifying the userid/password/domain when making a WebRequest. Without the proper credentials, the router returns an “401 unauthorized” response. The TextBox controls (textBox3, textBox4, textBox5) used below contain the user id, password, and domain for the login. The TextBox control for the router address (textBox1) is appended with “/FW_log.htm” to get the URI for the logs. Once the response is received, the program looks for strings that begin with “[ALLOW”. These are the records contained in the log.



   NetworkCredential myCred = new
   NetworkCredential(this.textBox3.Text, this.textBox4.Text, this.textBox5.Text);
   CredentialCache myCache = new CredentialCache();

   myCache.Add(new Uri(this.textBox1.Text), "Basic", myCred);

   HttpWebRequest  request  = (HttpWebRequest)
   WebRequest.Create(this.textBox1.Text + "/FW_log.htm");
   request.Credentials = myCache;
   try
   {
      HttpWebResponse response = (HttpWebResponse)
         request.GetResponse();
      Stream resStream = response.GetResponseStream();

netgearmonitor

Leave a comment

Your email address will not be published.