Skip to content

Instantly share code, notes, and snippets.

@rmamba
Last active August 29, 2015 13:58
Show Gist options
  • Save rmamba/9970901 to your computer and use it in GitHub Desktop.
Save rmamba/9970901 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys
import telnetlib
import socket
import os.path
import urllib2
import json
try:
TLDs = None
J = None
server = None
domain = None
if len(sys.argv)<2:
print "Usage: whois.py domain.com"
quit()
domain = sys.argv[1]
if os.path.isfile('TLDs.json'):
jf = open('TLDs.json','rb')
J = jf.read()
jf.close()
else:
jdata = urllib2.urlopen("https://gist.githubusercontent.com/rmamba/9952063/raw/67fbb082c04b581eb75cd251ccfaddd72d5b3726/TLDs")
J = jdata.read()
jf = open('TLDs.json','wb')
jf.write(J)
jf.close()
TLDs = json.loads(J)
D = domain.split('.')
if D[-1] in TLDs.keys():
server = TLDs[D[-1]]
if D[-2]+"."+D[-1] in TLDs.keys():
server = TLDs[D[-2]+"."+D[-1]]
if not server:
print "Server not found!!!"
quit()
print "Connecting to " + server + ":43"
tn = telnetlib.Telnet(server, 43)
print "Waiting for escape character"
#Wait until connected or timedout after 2 seconds
tn.read_until("'^]'.", 2)
print "Sending "+ domain + " ..."
tn.write(domain + "\r\n")
print "Results:"
print tn.read_all()
except socket.error, e:
print "Socket error: ", e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment