Skip to content

Commit 33de444

Browse files
authored
Merge pull request #5 from J-Run/master
Add CSUBNET address logging
2 parents c4e752c + fd5adba commit 33de444

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

dnschef.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,25 @@ def parse(self, data):
125125
# Create a custom response to the query
126126
response = DNSRecord(DNSHeader(id=d.header.id, bitmap=d.header.bitmap, qr=1, aa=1, ra=1), q=d.q)
127127

128+
if options.csubnet:
129+
if len(d.ar):
130+
for rdata in d.ar[0].rdata:
131+
if rdata.code == 8:
132+
netmask = rdata.data[2]
133+
client_subnet = ""
134+
for i in range(4, len(rdata.data)):
135+
client_subnet += str(rdata.data[i])
136+
if i < len(rdata.data) - 1:
137+
client_subnet += "."
138+
for m in range(i, 7):
139+
client_subnet += ".0"
140+
log.info(f"{self.client_address[0]} [{client_subnet}/{netmask}]: cooking the response of type '{qtype}' for {qname} to {fake_record}")
141+
128142
log.info(f"{self.client_address[0]}: cooking the response of type '{qtype}' for {qname} to {fake_record}")
129143

144+
145+
146+
130147
# IPv6 needs additional work before inclusion:
131148
if qtype == "AAAA":
132149
ipv6_hex_tuple = list(map(int, ip_address(fake_record).packed))
@@ -479,6 +496,7 @@ def start_cooking(interface, nametodns, nameservers, tcp=False, ipv6=False, port
479496
rungroup.add_argument("-6","--ipv6", action="store_true", default=False, help="Run in IPv6 mode.")
480497
rungroup.add_argument("-p","--port", metavar="53", default="53", help='Port number to listen for DNS requests.')
481498
rungroup.add_argument("-q", "--quiet", action="store_false", dest="verbose", default=True, help="Don't show headers.")
499+
rungroup.add_argument("--csubnet", action="store_true", default=False, help="Log CSUBNET addr.")
482500

483501
options = parser.parse_args()
484502

0 commit comments

Comments
 (0)