域名系统(DNS)是互联网的一项服务,它作为将域名和IP地址相互映射的一个分布式数据库,能够使人更方便地访问互联网。当一个域名拥有多家DNS服务商时,意味着该域名的解析服务由多个不同的DNS服务器提供。
import dns.resolver
def query_domain(domain):
try:
answers = dns.resolver.resolve(domain, 'A')
for rdata in answers:
print(f'{domain} resolved to {rdata}')
except dns.resolver.NXDOMAIN:
print(f'{domain} does not exist.')
except dns.resolver.NoAnswer:
print(f'{domain} has no A records.')
except dns.resolver.Timeout:
print(f'Query timed out for {domain}.')
except Exception as e:
print(f'An error occurred: {e}')
query_domain('example.com')
领取专属 10元无门槛券
手把手带您无忧上云