Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: src/miniFakeDns.py

Issue 6474028: [MiniFakeDns] Translate logging, reduce verbosity in INFO logs (Closed) Base URL: http://git.chromium.org/git/minifakedns.git@master
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 import socket, threading, time 3 import logging, socket, threading, time
4 4
5 class DNSQuery: 5 class DNSQuery:
6 TYPE = '\x00\x01' # An 'A' record 6 TYPE = '\x00\x01' # An 'A' record
7 CLASS = '\x00\x01' # of the Internet class 7 CLASS = '\x00\x01' # of the Internet class
8 TTL = '\x00\x00\x00\x3c' # 60 hops 8 TTL = '\x00\x00\x00\x3c' # 60 hops
9 RESOURCE_DATA_LENGTH = '\x00\x04' # 4 bytes 9 RESOURCE_DATA_LENGTH = '\x00\x04' # 4 bytes
10 10
11 11
12 def __init__(self, data): 12 def __init__(self, data):
13 self.data=data 13 self.data=data
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 Example use: 69 Example use:
70 server = DNSServer(fake_ip='127.0.0.1') 70 server = DNSServer(fake_ip='127.0.0.1')
71 stopper = threading.Event() 71 stopper = threading.Event()
72 thread = threading.Thread(target=server.run, args=(stopper,)) 72 thread = threading.Thread(target=server.run, args=(stopper,))
73 . 73 .
74 . 74 .
75 . 75 .
76 stopper.set() 76 stopper.set()
77 """ 77 """
78 self._udps.bind((self._address, self._port)) 78 self._udps.bind((self._address, self._port))
79 print 'miniFakeDns listening on port %d' % self._port 79 logging.info('miniFakeDns listening on port %d' % self._port)
80 self._udps.settimeout(1) 80 self._udps.settimeout(1)
81 while not stop.is_set(): 81 while not stop.is_set():
82 try: 82 try:
83 data, addr = self._udps.recvfrom(1500) 83 data, addr = self._udps.recvfrom(1500)
84 p=DNSQuery(data) 84 p=DNSQuery(data)
85 self._udps.sendto(p.respuesta(self._fake_ip), addr) 85 self._udps.sendto(p.respuesta(self._fake_ip), addr)
86 print 'Respuesta: %s -> %s' % (p.dominio, self._fake_ip) 86 logging.debug('Response: %s -> %s' % (p.dominio, self._fake_ip))
87 except socket.timeout: 87 except socket.timeout:
88 pass 88 pass
89 89
90 90
91 def __stop(self): 91 def __stop(self):
92 self._udps.close() 92 self._udps.close()
93 93
94 94
95 if __name__ == '__main__': 95 if __name__ == '__main__':
96 ip='192.168.1.1' 96 ip='192.168.1.1'
97 print 'pyminifakeDNS:: dom.query. 60 IN A %s' % ip 97 print 'pyminifakeDNS:: dom.query. 60 IN A %s' % ip
98 server = DNSServer(fake_ip=ip) 98 server = DNSServer(fake_ip=ip)
99 stopper = threading.Event() 99 stopper = threading.Event()
100 thread = threading.Thread(target=server.run, args=(stopper,)) 100 thread = threading.Thread(target=server.run, args=(stopper,))
101 try: 101 try:
102 thread.start() 102 thread.start()
103 while 1: 103 while 1:
104 time.sleep(1) 104 time.sleep(1)
105 except KeyboardInterrupt: 105 except KeyboardInterrupt:
106 print 'stopping thread' 106 print 'stopping thread'
107 stopper.set() 107 stopper.set()
108 thread.join() 108 thread.join()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698