- Receive a typed URL via keyboard
- Pings its URL
- Returns the ip (if any) of the URL you typed
Eg: Enter a 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
Do you want to continue? [S] im [N] ao
Now whenever I run the program it gives the answer "up" regardless of what is typed in the site field, with this the following message occurs:
Enter the site: www.ggghhh.com.br www.ggghhh.com.br is up! Traceback (most recent call last): File "C: \ Users \ cwo \ Downloads \ python \ WORK.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])