def check_ipaddr(dst, version=4):
'''
Receive a hostname or IP address string and return a validated
IP and fqdn if either can be found
'''
family = version_to_family(version)
for res in socket.getaddrinfo(dst, 0, family, socket.SOCK_STREAM, 0,
socket.AI_PASSIVE | socket.AI_CANONNAME):
family, socktype, proto, canonname, sa = res
try:
addr = ipaddress.ip_address(unicode(sa[0]))
except NameError:
addr = ipaddress.ip_address(sa[0])
return addr, canonname
评论列表
文章目录