From powershell, I can run Get-DnsServerResourceRecord -zonename "test.com" to get all records in the zone.
I can load all zones to a variable, and use a for loop to get all records in all zones.
What I want is all records from all zones with a record containing an IP address within a CIDR range.
Example: I want all records in all zones that have a value of 10.10.10.1/24 The return would hopefully contain zone, record type, record name, and value E.G. temp.com, A Record, www, 10.10.10.10 test.org, cname, host1, 10.10.10.25 etc
The first thing to note is that when querying DNS, each type of DNS record has a different property to query, so there is no way to just query a record for anything matching "mydomain.foo" and get back all the CNAME, MX, TXT, NS records that might have that string. So the query below is specifically for finding IPv4 addresses in A records.
Since you're searching for a /24 the simplest option is to simply search for the first 3 octets. So :
You could with some string wrangling search for a subset of the /24, but since the IP addresses are strings not numbers, it gets complicated.
Note, the query bit itself is :
where the critical element is :
You can similarly query other record types using the other properties found within
RecordData
, some examples of which are :