Te sugerimos que revises esta respuesta en un entorno controlado antes de pasarlo a producción, saludos.
Ejemplo 1: dirección IP de Python ping
import os
ip_list =['8.8.8.8']for ip in ip_list:
response = os.popen(f"ping ip").read()if"Received = 4"in response:print(f"UP ip Ping Successful")else:print(f"DOWN ip Ping Unsuccessful")
Ejemplo 2: cómo hacer ping a un sitio web en Python
from os import system
print('1. Ping Google')print('2. Ping Yahoo')print('3. Ping custom URL')whileTrue:
key =int(input('Input your choice: '))if key ==1:
system("ping www.google.com")elif key ==2:
system("ping www.yahoo.com")elif key ==3:
url =input('Enter URL: ')
system("ping "+ url)else:print("Invalid Option!")
Ejemplo 3: ping de Python
import platform # For getting the operating system nameimport subprocess # For executing a shell commanddefping(host):"""
Returns True if host (str) responds to a ping request.
Remember that a host may not respond to a ping (ICMP) request even if the host name is valid.
"""# Option for the number of packets as a function of
param ='-n'if platform.system().lower()=='windows'else'-c'# Building the command. Ex: "ping -c 1 google.com"
command =['ping', param,'1', host]return subprocess.call(command)==0
Ejemplo 4: cómo obtener ping desde la computadora en PYTHON
st = Speedtest()print("Download:=>", st.download())print("upload:=>", st.upload())
st.get_servers([])print("Ping :=>", st.results.ping)
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)