The script is as follows:
#!/usr/bin/env python #coding:utf-8 import os,sys from socket import gethostbyname DOMAIN= "G:/PycharmProject/fullstack2/week1/domain.txt" def main(): #domain.txt stores a list of domain names that need to be parsed in batches, one per line with open(DOMAIN,'r') as f: for line in f.readlines(): try: host = gethostbyname(line.strip('\n')) except Exception as e: print e else: #result.txt stores the results of batch parsing and does not need to be created in advance with open('result.txt','a+') as r: r.write(line.strip('\n') + ' ') r.write(host + '\n') if __name__ == '__main__': main()
This script is not perfect, because the IP and domain name are bound, but the IP ping fails or the machine shuts down, the following error will occur
[Errno 11001] getaddrinfo failed [Errno 11001] getaddrinfo failed [Errno 11001] getaddrinfo failed [Errno 11001] getaddrinfo failed
And it is impossible to determine which domain name is not bound to the IP
refer to:
http://www.tiaozhanziwo.com/archives/166.html