def get_addresses(hostname) -> List[Union[IPv4Address, IPv6Address]]:
# Get DNS info
try:
a_records = subprocess.check_output(args=['dig', '+short', 'a', hostname],
stderr=subprocess.DEVNULL)
aaaa_records = subprocess.check_output(args=['dig', '+short', 'aaaa', hostname],
stderr=subprocess.DEVNULL)
dns_records = a_records + aaaa_records
dns_results = []
for line in dns_records.decode('utf-8').strip().split():
try:
dns_results.append(str(ip_address(line)))
except ValueError:
pass
except subprocess.CalledProcessError:
dns_results = []
return dns_results
评论列表
文章目录