måndag 6 september 2010

ASRock 330 CPU fan mod

The ASRock ION 330 is a great little computer, but the high pitch whining of the 30 mm CPU fan was beginning to annoy me. So inspired by this article I replaced the fan screws with rubber rivets. I have to say it is much better now. The high pitch noise is gone and whatever little sound is still coming from the fans does not bother me.

I managed to loosen the three fan screws with a pair of pliers, from the side so to speak, so I didn't have to remove the heatsinks.

torsdag 26 augusti 2010

C# code for rebooting a DIR-655 router

Here are the interesting part of an application a made to reboot my D-Link router. Lately my connection have been getting very slow about once a week and i need to do a hard reset to fix it. I have set Windows Scheduler to run this application every night. Hopefully my connection vill be more stable now.

I don't know if this works on other models or firmwares. My router has hardware version A3 and firmware version 1.30EU.

UPDATE: After downgrading to firmware version 1.21EU the router is rock solid and I no longer need this utility, but it was a fun exercise at least.

// Go to login page
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format("http://{0}/", ip));
request.Timeout = 10000;

string body = "";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
 using (Stream stream = response.GetResponseStream())
 {
  StreamReader sr = new StreamReader(stream);
  body = sr.ReadToEnd();
 }
}

// Get salt and authId from login page
string salt = "";
string authId = "";
if (!string.IsNullOrEmpty(body))
{
 salt = body.Substring(body.IndexOf("var salt = ", 0) + 12, 8);
 authId = body.Substring(body.IndexOf("&auth_id=", 0) + 9, 5);
}

string loginHash = CreateHash(salt, password);

// Login
request = (HttpWebRequest)WebRequest.Create(string.Format("http://{0}/post_login.xml?hash={1}&auth_code=&auth_id={2}", ip, loginHash, authId));

body = "";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
 using (Stream stream = response.GetResponseStream())
 {
  StreamReader sr = new StreamReader(stream);
  body = sr.ReadToEnd();
 }
}

if (!body.Contains("Status/Device_Info.shtml"))
{
 // Login failed
}


private string CreateHash(string salt, string password)
{
 password = password.PadRight(16, Convert.ToChar(1));

 string input = salt + password;
 input = input.PadRight(64, Convert.ToChar(1));

 string hash = CreateMd5Hash(input);

 return salt + hash;
}

private string CreateMd5Hash(string input)
{
 var md5 = System.Security.Cryptography.MD5.Create();
 byte[] bytes = md5.ComputeHash(System.Text.Encoding.ASCII.GetBytes(input));
 return BitConverter.ToString(bytes).Replace("-", "").ToLower();
}

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format("http://{0}/reboot.cgi?reset=false", ip));
request.Timeout = 10000;
request.GetResponse();

The application can be downloaded here. Requires .NET Framework 3.5.

tisdag 24 augusti 2010

Source code highlighting

Using SyntaxHighlighter and syntax highlighting tutorial for Blogger.


/**
* SyntaxHighlighter
*/
function foo()
{
    if (counter <= 10)
        return;
    // it works!
}


private string CreateHash(string salt, string password)
{
    password = password.PadRight(16, Convert.ToChar(1));

    string input = salt + password;
    input = input.PadRight(64, Convert.ToChar(1));

    string hash = CreateMd5Hash(input);

    return salt + hash;
}

private string CreateMd5Hash(string input)
{
    var md5 = System.Security.Cryptography.MD5.Create();
    byte[] bytes = md5.ComputeHash(System.Text.Encoding.ASCII.GetBytes(input));
    return BitConverter.ToString(bytes).Replace("-", "").ToLower();
}