Tuesday, March 9, 2010

A Small PING utility to keep the network awake

I recently set up a small home network on windows, and was using samba to access the same using Ubuntu.

I realized over a period of time that some computers on the network have a tendency to fall asleep, preventing me from being able to access shared data. A simple solution to this was a simple "ping". But the task of facing "access denied" and then running a terminal to ping the particular computer was getting too tedious. Moreover, since I have a wireless router in between, the IP addresses for all the machines keep hovering in an around my current IP address.

Today I decided that enough was enough, and I had to squash this issue once and for all. So I wrote something called "pingTEN" ('ten' being the reverse of 'net' .. heehee!)

Its a really simple utility which allows my computer to ping X number of IP addresses on either side of my current IP address. Since this operation can be a major CPU hog, you can also program Y number of seconds, for which the program will sleep once all the pings are complete. It performs a single packet quiet ping.

Since I usually have about two to three computers active on my home network at any time, I simply type this:

shell:~$python pingten.py 2 10

Now 2 (is X) and 10 (is Y). Another cute feature I've added is that everything that is put out on the console (if you're running it from the terminal), will be written down periodically into a file, with a timestamp. Why is this important?? Simply because, I can now choose to run this in the background (using the System > preferences > startup applications menu) and be able to monitor if it is still active. It runs as if it were a daemon or a background process.

If I simply open nautilus (or whatever file browser utility is available), I can actually see the file size changing from 270 bytes to 0 bytes to 270 bytes... and so on. With every set of pings, the file is overwritten with 270 bytes of data. The program then sleeps for ten seconds and rewrites the file when it wakes up, causing the size to get nullified.

Its a really simple way to keep track of my application, which I cannot see without the terminal.

Click here to download the source!

0 comments:

Post a Comment