- Recebe uma URL digitada via teclado
- Realiza um ping da respectiva URL
- Retorna o ip (se houver) da URL digitada
Ex.: Digite uma URL: www.google.com
Pinging www.google.com [172.217.162.164] with 32 bytes of data: Reply from 172.217.162.164: bytes=32 time=64ms TTL=54
Reply from 172.217.162.164: bytes=32 time=56ms TTL=54
Reply from 172.217.162.164: bytes=32 time=55ms TTL=54
Reply from 172.217.162.164: bytes=32 time=57ms TTL=54
Ping statistics for 172.217.162.164:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 55ms, Maximum = 64ms, Average = 58ms
www.google.com | 172.217.162.164
Deseja continuar? [S]im [N]ao
Agora sempre que executo o programa ele dá a resposta "up" independente do que seja digitado no campo site, com isso ocorre a seguinte mensagem:
Digite o site: www.ggghhh.com.br www.ggghhh.com.br is up! Traceback (most recent call last): File "C:\Users\cwo\Downloads\python\TRABALHO.py", line 22, in ip = socket.gethostbyname(hostname) socket.gaierror: [Errno 11004] getaddrinfo failed
import os
import subprocess
import socket
list_site = []
list_ip = []
hostname = ""
continuar = ""
while continuar != "nao":
hostname = str(input("Digite o site: "))
list_site.append(hostname)
response = os.system("ping -c4 " + hostname)
if response == 0:
print (hostname, 'is down!')
ip = 0
list_ip.append(0)
else:
print (hostname, 'is up!')
ip = socket.gethostbyname(hostname)
list_ip.append(ip)
continuar = str(input("Deseja digitar mais algum site? "))
for i in range(len(list_site)):
print(list_site[i], list_ip[i])