【发布时间】:2015-10-04 00:41:05
【问题描述】:
背景:我一直想尝试编写脚本,所以开始吧!
问题:当 gethostbyaddr 访问没有 DNS 条目的 IP 时,它会出错并且我的脚本无法继续。
这是我目前所拥有的:
import socket
file = 'ServerList'
f = open(file, 'r')
lines = f.readlines()
f.close()
for i in lines:
host = i.strip()
if socket.gethostbyaddr(host) return(True):
val1 = socket.gethostbyaddr(host)
print("%s - %s" % (host, val1))
else:
print ("%s - No Entry" % (host))
但它可能会出错,因为 return(True) 的语法不正确。
谁能帮忙?
谢谢, J
【问题讨论】:
-
if socket.gethostbyaddr(host):解决您的问题? -
如果提供的脚本对您有用,您是否尝试过?如果对您有帮助,请考虑将其作为可接受的答案。
标签: python sockets networking reverse-dns gethostbyaddr