Función simple para saber si un dominio o una ip están en línea.
Nota: Hasta ahora solo la he probado en linux
def do_ping(ip): print "HACIENDO PING A "+str(ip) response = os.system("ping -c 1 " + ip) if response == 0: print "HOST CONECTADO" return True else: print "HOST NO CONECTADO" return False
Ejemplos de uso de función
do_ping("192.168.151.1") HACIENDO PING A 192.168.151.1 PING 192.168.151.1 (192.168.151.1) 56(84) bytes of data. From 192.168.0.2 icmp_seq=1 Destination Host Unreachable HOST NO CONECTADO do_ping("192.168.151.254") HACIENDO PING A 192.168.151.254 PING 192.168.151.254 (192.168.151.254) 56(84) bytes of data. 64 bytes from 192.168.151.254: icmp_req=1 ttl=62 time=3.17 ms HOST CONECTADO