Skip to content

Instantly share code, notes, and snippets.

@cyberdelia
Created November 1, 2009 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberdelia/223639 to your computer and use it in GitHub Desktop.
Save cyberdelia/223639 to your computer and use it in GitHub Desktop.
Find every available domain from a dictionary
#!/usr/bin/env python
# encoding: utf-8
import sys, json, urllib
from optparse import OptionParser
def main():
parser = OptionParser()
parser.add_option("-e", "--extension", action="append", type="string", dest="extensions", help="specify domain extension", default=[])
parser.add_option("-a", "--availability", action="store", type="choice", choices=["taken", "maybe", "available", "unavailable", "tld"], dest="availability", help="specifiy level of availability", default="available")
parser.set_defaults(verbose=True)
(options, args) = parser.parse_args()
for line in sys.stdin:
domain = line.strip()
response = json.load(urllib.urlopen("http://domai.nr/api/json/search?q=%s" % domain))
for result in response['results']:
if result['availability'] in [options.availability]:
if options.extensions:
for ext in options.extensions:
if result["domain"].endswith(ext):
print result['domain']
else:
print result['domain']
if __name__ == '__main__':
try:
main()
except (KeyboardInterrupt, SystemExit):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment