-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdns_log_parse.py
37 lines (28 loc) · 894 Bytes
/
dns_log_parse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#encoding=utf-8
import ctypes
import re
import os
def parse_dns(filename):
file = open(filename,'r')
try:
lines = file.read()
stringlist = re.findall(r'Name\s+: \S+',lines)
stringlist = [re.sub(r'Name\s+: ','',string) for string in stringlist]
stringlist.remove('isatap')
for string in stringlist:
print string
except:
pass
finally:
file.close()
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
disable_file_system_redirection().__enter__()
parse_dns('c:/windows/system32/dnsrslvr.log')