import dns.resolver import requests import re import sys def get_ip_list(domain): try: cn = dns.resolver.query(domain, 'CNAME') for i in cn.response.answer: for j in i.items: cname_domain = j.to_text() print('%s ---> %s' % (domain, cname_domain)) except Exception as e: print('%s,%s' % (domain, e)) try: A = dns.resolver.query(domain, 'A') for i in A.response.answer: for j in i.items: ip_list.append(j.address) except: pass return ip_list def get_ip_belong(domain_ip): url = 'http://ip138.com/ips138.asp?ip=%s&action=2' % domain_ip resp = requests.get(url) resp.encoding = resp.apparent_encoding html = resp.text ip = re.findall(r'd{1,3}.d{1,3}.d{1,3}.d{1,3}', html) result = re.findall(r'(<li>.*?</li>)', html) belong = result[0][14:-5] print('%-*s--->%*s' % (18, ip[0], 20, belong)) if __name__ == '__main__': file_name = "domainList.txt" with open(file_name, 'r', encoding='utf-8') as f: domains = f.readlines() for domain in domains: get_ip_list(domain.rstrip())