Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check domains for records and stuff
#!/usr/bin/env python
# The py2 code below is an abomination that was slapped together in a matter of
# minutes to see if the internet was behaving as expected. It is utter garbage
# and should not be used by anyone. - @decidedlygray
import socket
import urllib2
import zipfile
import csv
# import time
domains = []
domains_didnt_resolve = []
resolved_count = 0
didnt_resolve_count = 0
def download_and_unzip_domains():
domains_file_url = 'http://s3.amazonaws.com/alexa-static/top-1m.csv.zip'
log_message('Downloading: ' + domains_file_url)
with open('top-1m.csv.zip','wb') as zip_file:
zip_file.write(urllib2.urlopen(domains_file_url).read())
zip_file.close()
log_message('Download finished')
log_message('Unzipping top-1m.csv.zip')
zip_file = zipfile.ZipFile('top-1m.csv.zip', 'r')
zip_file.extractall()
zip_file.close()
log_message('Unzipped to local working directory')
def run_hmmmm():
global domains
global resolved_count
global didnt_resolve_count
global domains_didnt_resolve
with open('top-1m.csv', 'rb') as csvfile:
domain_reader = csv.reader(csvfile, delimiter=',')
domains_processed = 0
for row in domain_reader:
domain = row[1]
log_message('TESTING: ' + domain)
try:
data = socket.gethostbyname_ex(domain)
resolved_count += 1
except socket.gaierror:
data = '! gaierror Exception while resolving ' + domain
didnt_resolve_count += 1
domains_didnt_resolve.append(domain)
log_message(data)
domains_processed += 1
if not domains_processed % 100:
log_message('--------------------------------------------------------------->')
log_message(' - CURRENT STATUS: RESOLVED:' + str(resolved_count)
+ ' DIDN''T RESOLVE:'+ str(didnt_resolve_count))
log_message(' - UNRESOLVED DOMAINS: ' + str(domains_didnt_resolve))
log_message('<---------------------------------------------------------------')
# time.sleep(1)
log_message('FINAL TALLY:')
log_message(' RESOLVED:' + str(resolved_count))
log_message(' DIDN''T RESOLVE:' + str(didnt_resolve_count))
log_message(' DOMAINS THAT DIDNT RESOLVE: ' + str(domains_didnt_resolve))
log_message('[...keep in mind some don''t resolve and that''s ok]')
def log_message(msg):
print('[*] ' + str(msg))
f = open('run_hmmmm_results.txt','a')
f.write(str(msg) + '\n')
f.close()
if __name__ == '__main__':
open('run_hmmmm_1m_results.txt','w').close()
download_and_unzip_domains()
run_hmmmm()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.