Thursday, October 15, 2009

Control your ASUS WL500g Premium from the command line

I have a nice router Asus WL500g Premium, but I can’t say the same about my Internet provider. Several times a day it breaks the Internet connection in the way my router couldn’t restore it, so I have to manually disconnect and re-connect it. This is tremendously hard because of poor router’s admin interface. So, because I’m still learning Haskell, I decided to create simple command-line utility that will reconnect my router to the WAN.

After first release, I split the project into two components: a library, which connects to the router, and several command-line tools, that runs my usual activities automatically. You can install them using cabal:

cabal install WL500gPLib
cabal install WL500gPControl

The WL500gP Library now could retrieve connection status, external IP address, DNS servers and log from the router, and could send connect, disconnect and clear log commands. I implemented all these operations in the Conn monad, which is simply Reader transformer over IO monad. This approach reduces boilerplate code and also adds automatic log off to the command chain.

The WL500gP Remote Control package have two executables, to work with router. WL500gPControl does everything, that library support. So to see log from the router, simply run:

WL500gPControl -l

To see all list of supported operations type:

WL500gPControl -h

The connection info (user name, password and host address) WL500gPControl takes from the $HOME/.wl500gp file, but it could be any other file specified in the command line as the second argument. The file format is following:

user: username
password: password
host: 192.168.1.1

The second script is very simple and I wrote it only to show connection status in my xmobar. It only prints connected or disconnected with color tags (green and red accordingly). Here is my config line from .xmobarrc:

Run Com "WL500gPStatus" ["-c", "$HOME/.wl500gp"] "Internet" 300

Conclusion

It took several hours to implement all these features, and from that time I never loaded my router’s admin page. And also I ensured that tagsoup is the great library for fast and dirty HTML parsing.

1 comment:

  1. Great post, but, a minor tpyo [sic]: you "split" the library, not "splat" the library.
    Don't worry, happens to me when I switch between BDS, BG Phonetic & US QWERTY...

    ReplyDelete