Pinging a bunch of devices in a go is a regular task every network or system admin comes across. Here is a python script to automate that
Script
===================
import subprocess
def ping_ip(ip):
(output, error) = subprocess.Popen((['ping', ip, '-c', '2']), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
#for windows use -n instead of -c after ping, ip.
if b'bytes from' in output:
return "UP"
elif b'Destination Host Unreachable' in output:
return "DOWN"
elif error:
return "DNS Error"
else:
return "UNKNOWN"
l = ''
with open('devices.txt') as f:
for ip in f:
ip = ip.strip('\n')
response = ping_ip(ip)
result = ('%s,%s \n' % (ip, response))
l = l+result
file = open('output.txt', 'w')
file.write(l)
file.close()
Nesta página do site você pode assistir ao vídeo on-line PFNA- Pinging bulk devices using python duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Srihari Yenugukonda 30 Novembro 2018, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 3,386 vezes e gostou 58 espectadores. Boa visualização!