Tuesday, February 8, 2011

Adventures in Python code.

My Unisa studies have led me to the Python programming language, as mentioned before. Since then I have endeavoured to apply my knowledge on as many fronts as I can.

 

One of the first things I have done is to create a very simple host monitor.

 

Of course I could do this without Python, but where’s the science in that J ?

Python has a nice feature that allows you to run an OS command and write the results back to a variable. If I am not mistaken many other scripting languages have similar features.

 

So I do something simple like:

variable = os.popen(“ping hostname”).read()

 

This was the easy part. The parts that kept me busy were things like parsing strings for certain characters, saving results to external files, loading previous results and doing comparisons with them etc.

It’s still a work in progress, but it works.

 

The final bit was to import the results files into Excel to give me a visual of hosts on my network, which worked like a charm! Set the links to update every few minutes, schedule the script to run in the background, and you have a live view of your network!

 

I won’t put the entire set of scripts here since it is really basic stuff (and I would be showing how amateur I still am), but maybe later I’ll consider it J.

 

 

 

 

No comments:

Post a Comment