Skip to content

Instantly share code, notes, and snippets.

@Misterguruman
Created October 14, 2022 16:47
Show Gist options
  • Save Misterguruman/c94ca8438ee55c4b41df444b40fe2be1 to your computer and use it in GitHub Desktop.
Save Misterguruman/c94ca8438ee55c4b41df444b40fe2be1 to your computer and use it in GitHub Desktop.
A script written to ping a select group of IP Addresses to look for devices being down during a copier deployment
#!/usr/bin/python
import pyping, time, datetime
log_file = open('log.txt', "a")
def log(ip):
ts = time.time()
time_stamp = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
log_file.write(time_stamp + ' : ' + ip + '\n')
def test(ip):
response = pyping.ping(ip)
if response.ret_code == 0:
return True
else:
return False
file = open('iplist.txt', 'r')
total = len(file.readlines())
count = 1
file = open('iplist.txt', 'r')
for line in file:
line = line[0:-1]
try:
res = test(line)
except:
res = False
if res:
print str(count) + '/' + str(total) + ' ' + line + ' is reachable'
else:
print str(count) + '/' + str(total )+ ' ' + line + ' is not reachable'
log(line)
count = count + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment