If you have a TelkomSpeedy ADSL connection, oftenlly you’ll check your internet account usage. The bad thing is, you need to access telkom’s website download their huge flash just for view a couple lines of information about bandwith limit and usage. So, I’ve create a little javascript application for viewing current TelkomSpeedy usage. I mean, just the usage

This little script is utilizing the useful XMLHttpRequest and Javascript capabilities. The XMLHTTP object will do all the HTTP communication. This javascript can be run in your Windows Box using WScript.exe or CScript.exe, this two apps is shipped with your Windows instalation.

Usage

You can directly download the scripts here. Just edit the files with notepad to change the username and password with your speedy account username and password. And then, connect to internet with your speedy account, run the file by double-click it.

Here’s the screenshot:

For developers, here a little bit explanation about the script. First we create the xmlhttp object

var xmlhttp = false;

// create xmlhttp object
try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
  try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch(e) {
    // no xml http, bail
    WScript.Echo("Error, cannot create XMLHTTP object");
    WScript.Quit();
  }
}

And then, we need to send the login information, and retrieve the session cookie

var cookie = '';
var logged_in = false;

xmlhttp.open("POST", "http://divre5.telkomspeedy.com/session.php", false);
xmlhttp.onreadystatechange = function() {
  if (xmlhttp.readyState==4) {
    // retrieve session cookie
    cookie = xmlhttp.getResponseHeader('set-cookie');
    //check for login status
    body = xmlhttp.responseText;
    if (body.match(/location.href='/?'/)) {
      logged_in = true;
    } else {
      WScript.Echo("Error, login failed!");
      WScript.Quit();
    }
  }
}
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send('username='+username+'&password='+password);

When our loggin success, their website gives a JS redirection code:

location.href='/?';

So we just need to follow their redirection and parse the speedy bandwith info.

xmlhttp.open("POST", "http://divre5.telkomspeedy.com/?", false);
xmlhttp.onreadystatechange = function() {
  if (xmlhttp.readyState==4) {
    cookie = xmlhttp.getResponseHeader('set-cookie');
    body = xmlhttp.responseText;
    // retrieve speedy usage
    pos = body.indexOf('Sisa Limit');
    limit = body.substring(pos + 33, pos + 38);
    pos = body.indexOf('Pemakaian');
    used = body.substring(pos + 32, pos + 37);
    WScript.Echo("Speedy Usage For: " + username + "nSisa Limit: " + limit + "%nTerpakai  : " + used + "%" );
  }
}
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Cookie", cookie);
xmlhttp.send('');

And there’s we grep the useful information of speedy usage, minus downloading the image
and javascript.

Attachment