需求描述
有很多域名需要解析到A记录,有的需要解析到CNAME记录,以下两个函数解决这个问题
import dns.resolver def get_a_answer(vDomain): try: vIP = dns.resolver.query(vDomain, 'A') return str(vIP[0]) except Exception as e: print(e) print("ERROR MARK-6dDC0e1394DaEb3E") print("ERROR WRONG function get_a_answer() aDomainName -- aIP") return '1.1.1.1' def get_cname_answer(vDomain): try: vCName = dns.resolver.query(vDomain, 'CNAME') return str(vCName[0].target).strip('.') except Exception as e: print(e) print("ERROR MARK-Efba08cfd382Aa61") print("ERROR WRONG function get_cname_answer() aDomainName -- aCName") return 'www.some.com'