PFNA- Pinging bulk devices using python

Publicado el: 30 noviembre 2018
en el canal de: Srihari Yenugukonda
3,386
58

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()


En esta página del sitio puede ver el video en línea PFNA- Pinging bulk devices using python de Duración hora minuto segunda en buena calidad , que subió el usuario Srihari Yenugukonda 30 noviembre 2018, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 3,386 veces y le gustó 58 a los espectadores. Disfruta viendo!