Reputation: 115
I'm attempting to resolve the hostnames I have in a text file to IPs using sockets.
file.txt:
google.com
yahoo.com
iliketurtles.com
import socket
with open("file.txt", "r") as ins:
for line in ins:
print socket.gethostbyname(line.strip())
I'm getting the following gaierror:
print socket.gethostbyname(line.strip()) socket.gaierror: [Errno 8] nodename nor servname provided, or not known
What do I need to do differently to resolve the hostname on each line of the file and print to standard output?
Thanks in advance!
Upvotes: 0
Views: 936
Reputation: 2427
This code works for me. Sounds like it's a network issue. Check your internet connection - try to ping this servers and check that your DNS server works correctly.
Upvotes: 1