Skip to content

Instantly share code, notes, and snippets.

@weppos
Created June 7, 2012 18:30
Show Gist options
  • Save weppos/2890637 to your computer and use it in GitHub Desktop.
Save weppos/2890637 to your computer and use it in GitHub Desktop.

Revisions

  1. weppos revised this gist Jun 7, 2012. No changes.
  2. weppos created this gist Jun 7, 2012.
    24 changes: 24 additions & 0 deletions robowhois.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    import urllib2

    class RoboWhois:
    def __init__(self, api_key):
    self.username = api_key
    self.password = "X"

    def whois(self, domain):
    template = "http://api.robowhois.com/whois/%s"

    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, "http://api.robowhois.com/", self.username, self.password)
    handler = urllib2.HTTPBasicAuthHandler(passman)
    opener = urllib2.build_opener(handler)
    request = urllib2.Request(template % domain)
    response = opener.open(request)

    return response.read()


    # Example usage:
    #
    # robowhois = RoboWhois("YOUR_API_KEY")
    # print robowhois.whois("google.com")