I am creating an nslookup utility tool in python using socket.
Code:
import socket
while True:
try:
server = input()
ip_addr = socket.gethostbyname(server)
print(server, ip_addr, '\n')
except socket.gaierror:
print(server, 'unable to find ip')
break
returns:
google.com google.com 172.217.8.14
yahoo.com yahoo.com 98.138.219.231
domain.domain.domain domain.domain.domain unable to find ip
stackoverflow.com
So I want to hide the input so that only the following is displayed:
google.com 172.217.8.14
yahoo.com 98.138.219.231
domain.domain.domain unable to find ip
I also noticed that the last entry never gets ran through the script and I have to manually hit enter for "stackoverflow.com" to lookup the IP. Is there anyway around that?
I appreciate any help in advance! Thanks!