forked from githubmaidou/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdnslog.py
executable file
·32 lines (29 loc) · 871 Bytes
/
dnslog.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
#!/usr/bin/env python
import socket
from dnslib import DNSRecord
if __name__ == '__main__':
print('DNS Server Ready')
udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udps.bind(('0.0.0.0', 53))
try:
while True:
try:
packet, addr = udps.recvfrom(1024)
except ConnectionResetError:
continue # closed by client
client = addr
try:
client = socket.gethostbyaddr(addr[0])
except:
pass
d = DNSRecord.parse(packet)
found = str(d.q.qname) + ' from ' + str(client[0])
print found
#fd = open('dnslog', 'a+')
#fd.write(found+'\n')
#fd.close()
except KeyboardInterrupt:
pass
finally:
udps.close()
input('Press enter...')