Jul 28, 2010

Grab Dhiraagu ADSL usage from the terminal

UPDATE: There's a new version of the script out with more options and better configurability. Check it out HERE

Anybody who even occasionally stumbles on my blog should know full well by now that I have some personal beef with Dhiraagu. It's not that they suck..per se. It's just that I feel that they could, as a company, do much better.

Having said that, not having plain-text data available on the ADSL usage page (which incidentally has been trapped in a time-freeze-bubble since the 1960's) is just plain stupid on the part of whoever designed it. No matter though, where there is a will, there will be a way.

Previously I used to do it like this; Simply grabbing the graph image from the concerned page and popping it into eog so I can have a look.

wget --post-data "web_user=${username}&web_pass=${password}" -p http://dsl.dhivehinet.net.mv/login.php;eog ./dsl.dhivehinet.net.mv/comparision_graph.php;rm -r ./dsl.dhivehinet.net.mv

substitute ${username},${password} and eog as necessary.

But that wasn't enough..what If I wanted something in Conky or something to that effect? That would be a lot more convenient than having to look at that fart of a graph they have up there. So I came up with this simple solution.

SIMPLE but NOT ELEGANT... this is ugly, but it gets the job done.

#simple "hack" to grab and decode the ADSL usage
#graph from Dhiraagu. No magic going on here.
#require caca-utils (img2text)
#2010 KudaNai - http://kudanai.blogspot.com

username= #your username
password= #your password
package_allowance=20 #your_package allowance

cd /tmp
wget --quiet --post-data "web_user=${username}&web_pass=${password}" \
 -p http://dsl.dhivehinet.net.mv/login.php

gstring=$(img2txt -H 400 -W 4 -d none -f ansi dsl.dhivehinet.net.mv/comparision_graph.php) #yes...gstring
gtotal=$(echo "${gstring}" | grep 44 | wc -l) #blue colored line
gused=$(echo "${gstring}" | grep 43 | wc -l)  #yellow colored line
gbused=$(echo "scale=3;${gused} / ${gtotal} * ${package_allowance}" | bc -l)
gbleft=$(echo "scale=3;${package_allowance} - ${gbused}" | bc -l)

echo "used: \t${gbused} Gb\nleft:\t${gbleft}Gb\nAllow: \t${package_allowance}Gb"

rm -r dsl.dhivehinet.net.mv


Anonymous said...

interesting solution

Anonymous said...


SoE said...

so what? :S there's nothing more to it.

Anonymous said...

who can tel me, how to use this?

SoE said...

Sure. Follow up to the update post.

Post a Comment