I want to check a list of domains in a text file, whether they are registered or not. If they are not registered, I want to write those domains in another file. I wrote the code in python, but the main issue is that many registered domains are shown as not registered. Here is my code
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()