0% found this document useful (0 votes)
75 views

Pinger With Python

This Python script pings IP addresses sequentially within a range to check if hosts are responding. It uses regular expressions to parse ping output and identify response codes, then prints the response status of each host along with timestamps. The script exits if a host returns no response, since it requires both servers to be available for testing.

Uploaded by

Jitendra Yadav
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Pinger With Python

This Python script pings IP addresses sequentially within a range to check if hosts are responding. It uses regular expressions to parse ping output and identify response codes, then prints the response status of each host along with timestamps. The script exits if a host returns no response, since it requires both servers to be available for testing.

Uploaded by

Jitendra Yadav
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import os import re import time import sys

lifeline = re.compile(r"(\d) received") report = ("No response","Partial Response","Alive")

print "running pres setup method()" print time.ctime()

for host in range(128,130):

""" This loop runs individual and sequential pings. Since ping is implemented differently on different versions of Linux and Unix, you may need to change your ping options and the regular expression that it matches to get the correct results """

ip = "192.168.38."+str(host) pingaling = os.popen("ping -q -c2 "+ip,"r") print "Testing ",ip, sys.stdout.flush() while 1: line = pingaling.readline() if not line: break igot = re.findall(lifeline,line)

if igot: print report[int(igot[0])] status=int(igot[0]) if status == 0: print "ping failed this server, can not continue Test as both servers are not available" sys.exit() print status print time.ctime()

You might also like