A forgetful DSL modem….

Our household DSL modem, which is generally very reliable, occasionally, and mysteriously seems to forget a setting that I like to enable. I don’t know why, and I’ve never determined whether there’s a pattern to the loss or not (like maybe it’s every 30 days or some crazy thing like that).

Tonight, I finally decided to attempt to fix the problem in the simplest way I knew how: write some code.

Thankfully, the DSL modem has a simple web based management system with basic authentication.

So, I’ve set up a scheduled task on my Windows Home Server every 45 minutes to call into this console application:

using System;
using System.Net;
using System.IO;

namespace SendHttpCommand
{
    class Program
    {
        static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("SendHttpCommand requires 3 parameters in this order:");
                Console.WriteLine("    username");
                Console.WriteLine("    password");
                Console.WriteLine("    url");
                return -1;
            }
            Uri uri = new Uri(args[2]);
            HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;
            request.Credentials = new NetworkCredential(args[0], args[1]);
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            try
            {
                if (response != null)
                {
                    using (Stream receiveStream = response.GetResponseStream())
                    {
                        StreamReader readStream = new StreamReader(receiveStream);
                        string result = readStream.ReadToEnd();
                        Console.WriteLine(result);
                    }

                }
            }
            catch { }
            finally
            {
                response.Close();
            }

            return 0;
        }
    }
}

It literally was 10 minutes of coding, and 2 for testing. And now the DSL modem setting should generally always be set the way I like it (except for the 45 minute window). The program could be smaller by removing the response reading portion – but I thought it was more interesting that way, so I left it in.