![](/img/trans.png)
[英]Need help creating a Python script that reads hostnames from a txt file, pings the hostname, resolves the IP and prints it to another text file
[英]Python Parser to resolve IP address from hostnames in text file
我正在尝试使用套接字将文本文件中的主机名解析为IP。
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())
我收到以下gaierror:
打印socket.gethostbyname(line.strip())socket.gaierror:[错误号8]提供的节点名或服务名,或者未知
我需要采取其他措施来解析文件每一行上的主机名并打印到标准输出吗?
提前致谢!
该代码对我有用。 听起来像是网络问题。 检查您的互联网连接-尝试ping此服务器并检查您的DNS服务器是否正常运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.