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
try:
run_this  = command % (host %(x,y))
output = subprocess.check_output(run_this, shell=True,stderr=subprocess.STDOUT)
result.append(host%(x,y))
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
else:
print "Found no alive host"
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s