Skip to content

Instantly share code, notes, and snippets.

@b4ldr
Created July 17, 2014 19:22
Show Gist options
  • Save b4ldr/133ed978bb51bb519c62 to your computer and use it in GitHub Desktop.
Save b4ldr/133ed978bb51bb519c62 to your computer and use it in GitHub Desktop.
import dns.query
import dns.zone
import dns.tsigkeyring
import dns.tsig
import socket
import sys
import StringIO
def get_stats(xfr):
zone = StringIO.StringIO()
stats = {
'size' : 0,
'msg_count' : 0,
'rec_count' : 0,
'ans_count' : 0,
'add_count' : 0,
'ques_count' : 0,
'auth_count' : 0}
origin = dns.name.root
print type(xfr)
for message in xfr:
stats['auth_count'] += len(message.authority)
stats['add_count'] += len(message.additional)
stats['ques_count'] += len(message.question)
stats['ans_count'] += len(message.answer)
for ans in message.answer:
stats['rec_count'] += len(ans)
ans.to_wire(zone, origin=origin)
stats['msg_count'] += 1
stats['size'] += sys.getsizeof(zone.getvalue())
return stats
for ip in ['192.228.79.201', '193.0.14.129', '192.33.4.12', '192.5.5.241', '192.112.36.4', '193.0.14.129',
'192.0.32.132', '192.0.47.132']:
stats = get_stats(dns.query.xfr(ip, '.'))
host = socket.gethostbyaddr(ip)[0]
print '{}:{} messages, {} answers, {} records, {} Bytes'.format(host,
stats['msg_count'], stats['ans_count'], stats['rec_count'], stats['size'] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment