I use pywhois to determine if a domain name is registered or not. Here is my source code. (all permutations from a.net
to zzz.net
)
#!/usr/bin/env python
import whois #pip install python-whois
import string
import itertools
def main():
characters = list(string.ascii_lowercase)
##domain names generator
for r in range(1, 4) :
for name in itertools.permutations(characters, r) : #from 'a.net' to 'zzz.net'
url = ''.join(name) + '.net'
#check if a domain name is registered or not
try :
w = whois.whois(url)
except (whois.parser.PywhoisError): #NOT FOUND
print(url) #unregistered domain names?
if __name__ == '__main__':
main()
I got the following results:
jv.net
uli.net
vno.net
xni.net
However, all above domain names have already been registered. It is not accurate. Can anyone explain it? There are a lot of errors:
fgets: Connection reset by peer
connect: No route to host
connect: Network is unreachable
connect: Connection refused
Timeout.
There is an alternative way, reported here.
import socket
try:
socket.gethostbyname_ex(url)
except:
print(url) #unregistered domain names?
In speaking of speed, I use map
to parallel processing.
def select_unregisteredd_domain_names(self, domain_names):
#Parallelism using map
pool = ThreadPool(16) # Sets the pool size
results = pool.map(query_method(), domain_names)
pool.close() #close the pool and wait for the work to finish
pool.join()
return results