Skip to content

Instantly share code, notes, and snippets.

@loretoparisi
Created May 10, 2017 20:28
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 loretoparisi/61664b63b5d5e31cc554fac0cd861363 to your computer and use it in GitHub Desktop.
Save loretoparisi/61664b63b5d5e31cc554fac0cd861363 to your computer and use it in GitHub Desktop.
Telnet
#!/usr/bin/python
import os
import re
import sys
import telnetlib
import time
import datetime
def read_until(cue, timeout=2):
print tn.read_until(cue, timeout)
fileName = sys.argv[1]
os.system("clear")
f = open(fileName)
lines = f.readlines()
f.close()
print "****Domains"
print lines
print "\n***Hit a key to start analyzing"
#input = raw_input()
host = "whois.internic.net"
port = "43"
count = 0
n = datetime.datetime.now()
unix_time = time.mktime(n.timetuple())
for site in lines:
tn = telnetlib.Telnet(host,port)
tn.write(site + "\n")
sess_op = tn.read_all()
# pattern = "Domain"
# prog = re.compile(pattern)
# result = prog.search(sess_op)
print "\n***Domain:" + site
print "Step:"+str(count)
nx = datetime.datetime.now()
c_time = time.mktime(nx.timetuple())
elapsed = c_time - unix_time
print "Elapsed " + str(elapsed)
count=count+1
fname = site.replace('\n','') + '.txt'
outputFile = open( fname, 'w')
outputFile.write( sess_op )
outputFile.close()
# if result:
# print result.group(0)
tn.write("exit\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment