Skip to content

Commit

Permalink
fixed update_diskcache and use pprint when printing the entire whois …
Browse files Browse the repository at this point in the history
…record
  • Loading branch information
MarkBaggett committed Jun 20, 2018
1 parent 6071525 commit ff29fe3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ student@SEC573:~$ python domain_stats.py --preload 100 -a ~/Downloads/top-1m.csv
---
CHANGE LOG: Version 1.0 -> 1.1
*Update code to work in either Python2 or Python3
*Changed Default Content type of server response to TEXT.
*Added -d option which will load top 1000 domains from disk when -a top-1m.csv and --preload are not used.
Expand Down
4 changes: 3 additions & 1 deletion domain_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import os
import datetime
import pickle
from pprint import pformat

try:
import whois
Expand Down Expand Up @@ -119,7 +120,8 @@ def do_GET(self):
finally:
self.server.cache_lock.release()
if not fields:
self.wfile.write(str(domain_info).encode("latin-1"))
dinfo = pformat(domain_info)
self.wfile.write(dinfo.encode("latin-1"))
else:
if self.server.args.verbose: self.server.safe_print("processing fields %s" % (fields))
if domain_info.get('status','') == "NOT FOUND":
Expand Down
10 changes: 5 additions & 5 deletions update_diskcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,16 @@ def preload_domains(domain_list, delay=0.1):
parser.add_argument('-f','--file',help='Name of the file to write.',default="domain_cache.dst")
parser.add_argument('-a','--append',action="store_true", required=False,help='Append to existing file instead of overwriting.')
args = parser.parse_args()
print args

cache = {}
try:
alexa = open("top-1m.csv").readlines()[900:args.count]
alexa = open("top-1m.csv").readlines()[:args.count]
except Exception as e:
raise(Exception("Cant find your alexa top-1m.csv file. {0}".format(str(e))))

if args.append:
try:
fh = open("domain_cache.dst")
fh = open("domain_cache.dst","rb")
cache = pickle.load(fh)
fh.close()
except Exception as e:
Expand All @@ -65,8 +64,9 @@ def preload_domains(domain_list, delay=0.1):
preload_domains(alexa)

try:
fh = open(args.file,"w")
pickle.dump(cache, fh, protocol=2)
fh = open(args.file,"wb")
fh.write(pickle.dumps(cache,protocol=2))
fh.flush()
fh.close()
except Exception as e:
raise(Exception("Unable to create your disk cache file. {0}".format(str(e))))
Expand Down

0 comments on commit ff29fe3

Please sign in to comment.