]>
git.siccegge.de Git - software/wtfismyip.git/blob - nameserver.py
10 con
= sqlite3
.connect("tokens.sqlite")
13 con
.execute("CREATE TABLE IF NOT EXISTS token (token CHAR[32], ip VARCHAR[40])")
16 class DnsServerProtocol
:
17 def connection_made(self
, transport
):
18 self
.transport
= transport
20 def datagram_received(self
, data
, addr
):
21 # with open(os.path.join('packets', hashlib.sha224(data).hexdigest()), 'wb') as fd:
23 message
= dns
.message
.from_wire(data
)
24 for question
in message
.question
:
25 qname
= str(question
).split('.')[0]
28 con
.execute("INSERT INTO token (token, ip) VALUES (?, ?)", (qname
, addr
[0]))
31 response
= dns
.message
.make_response(message
)
32 self
.transport
.sendto(response
.to_wire(), addr
)
34 loop
= asyncio
.get_event_loop()
35 print("Starting UDP server")
36 # One protocol instance will be created to serve all client requests
37 listen
= loop
.create_datagram_endpoint(
38 DnsServerProtocol
, local_addr
=('fda3:c723:abcd:efe1:5054:ff:fec8:148e', 53))
39 transport
, protocol
= loop
.run_until_complete(listen
)
40 listen
= loop
.create_datagram_endpoint(
41 DnsServerProtocol
, local_addr
=('10.100.96.17', 53))
42 transport
, protocol
= loop
.run_until_complete(listen
)
47 except KeyboardInterrupt: