Skip to content

Commit

Permalink
adding option to log every dns queries or only the wanted ones
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperFola committed Jul 20, 2021
1 parent 4884a6d commit c7a14cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions config.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ interface=
root=example.com
domain=dns.example.com
host_ip=
log=* # or the DNS request type, eg TXT

[packets]
ttl=1
Expand Down
18 changes: 11 additions & 7 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,17 @@ def _dns_responder(self, pkt: IP):
packet = Packet(pkt, self.domain)
answer = None

self.logger.info(
"[DNS %s] Source %s:%i - on %s",
dnstypes[packet.question.qtype],
packet.src,
packet.sport,
packet.qname,
)
request_name = dnstypes[packet.question.qtype]

if self.config["server"]["log"] == "*" or \
self.config["server"]["log"] == request_name:
self.logger.info(
"[DNS %s] Source %s:%i - on %s",
request_name,
packet.src,
packet.sport,
packet.qname,
)

# reject every packet which isn't a DNS A/TXT query
if packet.is_valid_dnsquery(
Expand Down

0 comments on commit c7a14cc

Please sign in to comment.