背景:我一直想尝试编写脚本,所以就这样吧!
问题:当 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