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

Unified Diff: src/third_party/miniFakeDns/src/miniFakeDns.py

Issue 1444002: adding miniFakeDns, a python-based mini DNS server, to use in testing (Closed)
Patch Set: Created 10 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/third_party/miniFakeDns/README.chromium ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/third_party/miniFakeDns/src/miniFakeDns.py
diff --git a/src/third_party/miniFakeDns/src/miniFakeDns.py b/src/third_party/miniFakeDns/src/miniFakeDns.py
new file mode 100644
index 0000000000000000000000000000000000000000..8ffd4a47a0f89b456daf6241e4f0f0bf8f056c5a
--- /dev/null
+++ b/src/third_party/miniFakeDns/src/miniFakeDns.py
@@ -0,0 +1,43 @@
+import socket
+
+class DNSQuery:
+ def __init__(self, data):
+ self.data=data
+ self.dominio=''
+
+ tipo = (ord(data[2]) >> 3) & 15 # Opcode bits
+ if tipo == 0: # Standard query
+ ini=12
+ lon=ord(data[ini])
+ while lon != 0:
+ self.dominio+=data[ini+1:ini+lon+1]+'.'
+ ini+=lon+1
+ lon=ord(data[ini])
+
+ def respuesta(self, ip):
+ packet=''
+ if self.dominio:
+ packet+=self.data[:2] + "\x81\x80"
+ packet+=self.data[4:6] + self.data[4:6] + '\x00\x00\x00\x00' # Questions and Answers Counts
+ packet+=self.data[12:] # Original Domain Name Question
+ packet+='\xc0\x0c' # Pointer to domain name
+ packet+='\x00\x01\x00\x01\x00\x00\x00\x3c\x00\x04' # Response type, ttl and resource data length -> 4 bytes
+ packet+=str.join('',map(lambda x: chr(int(x)), ip.split('.'))) # 4bytes of IP
+ return packet
+
+if __name__ == '__main__':
+ ip='192.168.1.1'
+ print 'pyminifakeDNS:: dom.query. 60 IN A %s' % ip
+
+ udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ udps.bind(('',53))
+
+ try:
+ while 1:
+ data, addr = udps.recvfrom(1024)
+ p=DNSQuery(data)
+ udps.sendto(p.respuesta(ip), addr)
+ print 'Respuesta: %s -> %s' % (p.dominio, ip)
+ except KeyboardInterrupt:
+ print 'Finalizando'
+ udps.close()
« no previous file with comments | « src/third_party/miniFakeDns/README.chromium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698