Skip to content

Commit

Permalink
Create dns.py
Browse files Browse the repository at this point in the history
  • Loading branch information
0c0c0f authored Mar 31, 2017
1 parent 133c956 commit f5e29b8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions info/dns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/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])
fd = open('dnslog', 'a+')
fd.write(found+'\n')
fd.close()
except KeyboardInterrupt:
pass
finally:
udps.close()
input('Press enter...')

0 comments on commit f5e29b8

Please sign in to comment.