From c7a14cc8e82f834a0dc4c1aeb02b97965e3a568b Mon Sep 17 00:00:00 2001 From: Alexandre Plateau Date: Tue, 20 Jul 2021 23:20:03 +0200 Subject: [PATCH] adding option to log every dns queries or only the wanted ones --- config.ini.example | 1 + src/server.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/config.ini.example b/config.ini.example index 254044d..7385ddc 100644 --- a/config.ini.example +++ b/config.ini.example @@ -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 diff --git a/src/server.py b/src/server.py index 28274e9..e9c5bd1 100644 --- a/src/server.py +++ b/src/server.py @@ -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(