]> git.siccegge.de Git - software/wtfismyip.git/commitdiff
Add fake dns server master
authorroot <root@webhost.siccegge.dn>
Mon, 25 Dec 2017 21:45:31 +0000 (21:45 +0000)
committerroot <root@webhost.siccegge.dn>
Mon, 25 Dec 2017 21:46:43 +0000 (21:46 +0000)
fakedns.service [new file with mode: 0644]
nameserver.py [new file with mode: 0755]
wtfismyip.dn.zone [new file with mode: 0644]

diff --git a/fakedns.service b/fakedns.service
new file mode 100644 (file)
index 0000000..ab9aa6b
--- /dev/null
@@ -0,0 +1,10 @@
+[Unit]
+Description=Fake DNS Server
+
+[Service]
+ExecStart=/usr/bin/python3 ./nameserver.py
+NonBlocking=true
+WorkingDirectory=/srv/www/wtfismyip.dn/
+
+[Install]
+WantedBy=multi-user.target
diff --git a/nameserver.py b/nameserver.py
new file mode 100755 (executable)
index 0000000..e5a0ba1
--- /dev/null
@@ -0,0 +1,51 @@
+#!/usr/bin/python3
+
+import asyncio
+import hashlib
+import os.path
+
+import dns.message
+
+import sqlite3
+con = sqlite3.connect("tokens.sqlite")
+
+with con:
+    con.execute("CREATE TABLE IF NOT EXISTS token (token   CHAR[32], ip   VARCHAR[40])")
+
+
+class DnsServerProtocol:
+    def connection_made(self, transport):
+        self.transport = transport
+
+    def datagram_received(self, data, addr):
+        # with open(os.path.join('packets', hashlib.sha224(data).hexdigest()), 'wb') as fd:
+        #     fd.write(data)
+        message = dns.message.from_wire(data)
+        for question in message.question:
+            qname = str(question).split('.')[0]
+            
+            with con:
+                con.execute("INSERT INTO token (token, ip) VALUES (?, ?)", (qname, addr[0]))
+
+            
+        response = dns.message.make_response(message)
+        self.transport.sendto(response.to_wire(), addr)
+
+loop = asyncio.get_event_loop()
+print("Starting UDP server")
+# One protocol instance will be created to serve all client requests
+listen = loop.create_datagram_endpoint(
+    DnsServerProtocol, local_addr=('fda3:c723:abcd:efe1:5054:ff:fec8:148e', 53))
+transport, protocol = loop.run_until_complete(listen)
+listen = loop.create_datagram_endpoint(
+    DnsServerProtocol, local_addr=('10.100.96.17', 53))
+transport, protocol = loop.run_until_complete(listen)
+
+
+try:
+    loop.run_forever()
+except KeyboardInterrupt:
+    pass
+
+transport.close()
+loop.close()
diff --git a/wtfismyip.dn.zone b/wtfismyip.dn.zone
new file mode 100644 (file)
index 0000000..2ce6147
--- /dev/null
@@ -0,0 +1,9 @@
+@      IN      A       10.100.96.17
+               AAAA    fda3:c723:abcd:efe1:5054:ff:fec8:148e
+
+www    IN      CNAME   wtfismyip.dn.
+v4     IN      A       10.100.96.17
+v6     IN      AAAA    fda3:c723:abcd:efe1:5054:ff:fec8:148e
+
+ns4    IN      NS      v4
+ns6    IN      NS      v6