Skip to content

Instantly share code, notes, and snippets.

@rmhsilva
Created August 31, 2017 09:40
Show Gist options
  • Save rmhsilva/7da04c5d5c832d7ba32b72e6bc03a556 to your computer and use it in GitHub Desktop.
Save rmhsilva/7da04c5d5c832d7ba32b72e6bc03a556 to your computer and use it in GitHub Desktop.
# Check domain availability
import time # https://docs.python.org/2/library/time.html#time.sleep
import unirest # http://unirest.io/python
import json # https://docs.python.org/2/library/json.html
AUTH_TOKEN = 'xxxxxxxxxx'
RATE_LIMIT = 11 # Seconds, based on a limit of 6 per minute, plus margin
WORDS = ['abc', 'bdlahecnuhfsjf']
TLDS = ['xyz']
# Enclout: https://www.enclout.com/api/v1/whois
def enclout_query(url):
'Get the json object for a url request'
tpl = 'https://www.enclout.com/api/v1/whois/show.json?auth_token={}&url={}'
try:
res = unirest.get(tpl.format(AUTH_TOKEN, url))
except Exception as e:
print 'error! '+e
time.sleep(RATE_LIMIT)
return {}
info = json.loads(res.raw_body)
if info.has_key(u'error') and info.error != u'':
print 'error in response!'
return {}
else:
return info
def enclout_test_available(obj):
'obj: json response object'
if not obj.has_key(u'domain_status'):
return False
if obj[u'domain_status'][u'status'] == u'available':
return True
else:
return False
def domain_available(url):
'wrapper to search'
return enclout_test_available(enclout_query(url))
def search(words, extensions):
'Check if a set of words + tlds are available'
res = {}
for i,ext in enumerate(extensions):
for j,w in enumerate(words):
domain = w+'.'+ext
res[domain] = domain_available(domain)
print '\rTesting domain {} of {}'.format(i*len(words) + j + 1, len(extensions)*len(words)),
time.sleep(RATE_LIMIT)
print '\n'
return [w for w, available in res.iteritems() if available is True]
if __name__ == '__main__':
results = search(WORDS, TLDS)
print 'Available: {} domains'.format(len(results))
print str(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment