[英]Python Parser to resolve IP address from hostnames in text file
I'm attempting to resolve the hostnames I have in a text file to IPs using sockets. 我正在尝试使用套接字将文本文件中的主机名解析为IP。
file.txt : 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: 我收到以下gaierror:
print socket.gethostbyname(line.strip()) socket.gaierror: [Errno 8] nodename nor servname provided, or not known 打印socket.gethostbyname(line.strip())socket.gaierror:[错误号8]提供的节点名或服务名,或者未知
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! 提前致谢!
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. 检查您的互联网连接-尝试ping此服务器并检查您的DNS服务器是否正常运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.