ping sweeping with python

This simple piece of script demostrates how to do a simple ping sweeping with python.

For some reasons, wordpress really messed up the identation…Still working on it…

import subprocess

host = "192.168.%d.%d" #change this
command = "ping -c 1 -w 1 %s"
result = list()

for x in range(188,189): #change this
for y in range (125,130): #change this
run_this  = command % (host %(x,y))
output = subprocess.check_output(run_this, shell=True,stderr=subprocess.STDOUT)
print "Host %s is alive" % (host %(x,y))
except subprocess.CalledProcessError as e:
print "Host %s is not alive" % (host %(x,y))

print "===Done==="
if len(result):
print "There is %d host(s) alive" % len(result)
for re in result:
print re
print "Found no alive host"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s