Google
 
Web pyadmin.blogspot.com

Tuesday, May 02, 2006

An admin friendly ping

When i was working, I just want to ping some machines.And offcourse the machines are from other networks(otherwise i can use broadcast).So one way i found is that i can write a simple shell script which does the ping to the individual systems, but what about if u are having some 100 systems and all takes time more that 2 seconds to get a response?
here comes an alternative!!!!! a threaded ping, offcourse using python
#!/usr/bin/python
import os
import re
import time
import sys
from threading import Thread

class ping(Thread):
def __init__ (self,ip):
Thread.__init__(self)
self.ip = ip
self.status = -1
def run(self):
pingseq = os.popen("ping -q -c2 "+self.ip,"r")
while 1:
line = pingseq.readline()
if not line: break
result = re.findall(ping.getstatus,line)
if result:
self.status = int(result[0])

ping.getstatus = re.compile(r"(\d) received")
output = ("Not responding","Partial Response","Responding")

print time.ctime()

pinglist = []

for host in range(100,120):
ip = "10.200.9."+str(host)
current = ping(ip)
pinglist.append(current)
current.start()

for pingle in pinglist:
pingle.join()
print "Status from ",pingle.ip,"is",output[pingle.status]

print time.ctime()

1 Comments:

At 9:58 AM, Blogger Vineesh Kumar said...

Dear kiwi,
I dont think there's a standard ping module in python(offcourse my knowlwdge may be primitive), but while searching i come onto the following link,This is a robust ping program i feels, from the site
http://gnist.org/~lars/code/ping/

 

Post a Comment

<< Home