Skip to content

Instantly share code, notes, and snippets.

@whym
Created October 29, 2009 04:07
Show Gist options
  • Select an option

  • Save whym/221137 to your computer and use it in GitHub Desktop.

Select an option

Save whym/221137 to your computer and use it in GitHub Desktop.
#!python
# -*- encoding: utf-8 -*-
# DNS log converter from Microsoft DNS to namebench
# INPUT:
# 20091029 11:49:01 848 PACKET 02728D00 UDP Rcv 133.11.34.152 053d Q [0001 D NOERROR] A (6)images(8)slashdot(2)jp(0)
# OUTPUT:
# domain://images.slashdot.jp
import os,sys
import re
logpath = os.path.join(u'xxx',u'dns.txt')
outpath = os.path.join(u'xxx',u'dnsx.txt')
out = open(outpath, 'w')
for line in open(logpath, 'rb'):
line = line.strip()
res = re.search(r'NOERROR\]\s[A-Z]+\s+(\S+)',line)
if res != None:
domain = 'domain://' + re.sub(r'\(\d+\)', '.', res.group(1)).strip('.')
out.write(domain + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment