Python Monitoring Program


8 posts
by stevo_300 » Thu Jun 28, 2012 12:27 pm
Hi All,

I recently took delivery of my RPi, I have also taken the opportunity to create a program that will monitor the IP addresses on my network.

I have got to the basics in place. It scrolls through each IP address in our range, determines whether it is up or down depending on a response from a ping and also gets the fqdn of the machine that it Pings using:
Code: Select all
socket.gethostbyaddr('IPADDRESS')[0]


Here comes the tricky bit that I am really struggling with. I would like to also get the following from the connected devices where applicable:

manufacturer
operating system
current logged on user

I guess my question is, could somebody point me in the right direction to uncover these details? so far all of my searches have come up dry. I did find a wmi.py module however that only works when running python on a windows host, rather than on a linux host.

Thanks
Steve
User avatar
Posts: 33
Joined: Thu Jan 26, 2012 9:38 am
by Gibble » Thu Jun 28, 2012 12:41 pm
I'm not sure if that information would be readily available by default ? I guess it would depend on what the devices are that you are trying to probe, and what information they could be configured to provide.

Some may not even respond to a ping, depending on how they are configured.

Maybe if you provide a bit more info on what the other devices are (if you know), we may be able to help a bit more specifically.
Posts: 56
Joined: Wed May 09, 2012 9:52 am
by stevo_300 » Thu Jun 28, 2012 12:58 pm
Thanks for the reply Gibble,

Mostly they are windows machines (mainly workstations running Windows 7, some servers both physical and virtual running server 2008r2)

as for network devices, we have canon printers, zyxel switches (potentially soon some huawei switches), a juniper router

to be honest the network devices arent that important at present, but if I could get them to allow reporting of a few details that would be good.
User avatar
Posts: 33
Joined: Thu Jan 26, 2012 9:38 am
by andyl » Thu Jun 28, 2012 1:36 pm
It is difficult to do OS detection.

nmap does it - see http://nmap.org/book/man-os-detection.html
You will not be able to use their code - it is in C and is non-trivial.
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am
by stevo_300 » Thu Jun 28, 2012 1:48 pm
hmm seems like an overly tricky way to go....

could this scenario work...

although the script will be running from the Pi,

could I run a python command based on a remote machine?

basically what I am thinking is to install python onto a windows machine, so it can then access the wmi controls. and call the script from my pi to recover the output from the script.

I realise that I could just be clutching at straws here...
User avatar
Posts: 33
Joined: Thu Jan 26, 2012 9:38 am
by Gibble » Thu Jun 28, 2012 2:58 pm
I'm a little out of touch, but I wonder if SNMP could be configured on remote devices and then queried via Python and snmp on the Pi.
Posts: 56
Joined: Wed May 09, 2012 9:52 am
by stevo_300 » Thu Jun 28, 2012 3:13 pm
That is a very good idea,

I will investigate
User avatar
Posts: 33
Joined: Thu Jan 26, 2012 9:38 am
by wrhii » Thu Jun 28, 2012 8:12 pm
stevo_300 wrote:Here comes the tricky bit that I am really struggling with. I would like to also get the following from the connected devices where applicable:

manufacturer
operating system
current logged on user


Manufacturer and Operating System I believe are part of the SNMP information by default, but not certain of the Currently Logged on User. This is, of course, assuming that the offending device supports SNMP, which not everything does by default.

See also: http://en.wikipedia.org/wiki/Snmp. After a brief search I found http://pysnmp.sourceforge.net/ which says it is an SNMP library for Python.
Posts: 66
Joined: Fri Nov 18, 2011 1:47 am