批量过期的域名检查程序

时间:2017-11-13 04:47:15

标签: python python-sockets

我想查看文本文件中的域列表,无论它们是否已注册。如果他们没有注册,我想在另一个文件中写这些域。我在python中编写了代码,但主要问题是许多注册域显示为未注册。这是我的代码

import sys
import socket
from multiprocessing.pool import ThreadPool

def domainChecker(url):
    url=url.strip()
    try:    
        socket.gethostbyname_ex(url)
        return None
    except:
        return url

def main():
    pool = ThreadPool(5)
    urls=[]
    with open('domains.txt') as fp:
        for line in fp:
            urls.append(line)
    results = pool.map(domainChecker, urls)
    pool.close()
    pool.join()
    myfile = open('result.txt', 'w')
    for url in results:
        myfile.write("%s\n" % url)
    myfile.close    
    print("Completed")

if __name__ == '__main__':
    main()

0 个答案:

没有答案