Skip to content

Commit 562fd01

Browse files
authored
Create DNS Report (#8)
1 parent 8a7c1d5 commit 562fd01

6 files changed

Lines changed: 102784 additions & 30 deletions

File tree

AGENTS.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ The project is composed of three main Go-based command-line tools:
2323
## Workspace
2424

2525
* Use `./workspace` as a place to install tools and output binaries and intermediate results.
26-
* Use `./workspace/.venv` for Python installs. Do not install anything globally.
26+
* Use `./.venv` for Python installs. Do not install anything globally.
27+
28+
### Python Environment Setup
29+
30+
To set up the Python environment using `uv`, run the following commands from the project root:
31+
32+
```bash
33+
uv venv
34+
uv pip install -r requirements.txt
35+
```
2736

2837
---
2938
*The domain list used for the analysis is the [Tranco list](https://tranco-list.eu/).*

dnsreport/domains-top10000.csv

Lines changed: 9955 additions & 0 deletions
Large diffs are not rendered by default.

dnsreport/main.go

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -230,44 +230,48 @@ func annotateDomains(sem *semaphore.Weighted, client *dns.Client, domainsFilenam
230230
go func(td tranco.Domain) {
231231
defer sem.Release(1)
232232
defer domainsWg.Done()
233-
msg := new(dns.Msg)
234-
msg.SetQuestion(dns.Fqdn(td.Name), dns.TypeSOA)
235-
msg.RecursionDesired = true
236-
233+
// Get SOA and CNAME for the domain. We need the SOA to get the authoritative nameservers, and we want to know the CNAME if it exists.
234+
cname := td.Name
235+
soa := ""
237236
slog.Info("Collecting SOA for domain", "rank", td.Rank, "name", td.Name)
238-
r, _, err := client.Exchange(msg, resolverAddress)
237+
soaRequest := new(dns.Msg)
238+
soaRequest.SetQuestion(dns.Fqdn(td.Name), dns.TypeSOA)
239+
soaRequest.RecursionDesired = true
240+
soaResponse, _, err := client.Exchange(soaRequest, resolverAddress)
239241
if err != nil {
240242
slog.Error("SOA query failed", "domain", td.Name, "type", dns.TypeToString[dns.TypeSOA], "error", err)
241-
return
242-
}
243-
cname := td.Name
244-
soa := ""
245-
for _, answer := range r.Answer {
246-
if cnameRR, ok := answer.(*dns.CNAME); ok {
247-
cname = cnameRR.Target
248-
}
249-
if soaRR, ok := answer.(*dns.SOA); ok {
250-
soa = soaRR.Hdr.Name
251-
}
252-
}
253-
if soa == "" {
254-
for _, ns := range r.Ns {
255-
if soaRR, ok := ns.(*dns.SOA); ok {
243+
} else {
244+
for _, answer := range soaResponse.Answer {
245+
if cnameRR, ok := answer.(*dns.CNAME); ok {
246+
cname = cnameRR.Target
247+
}
248+
if soaRR, ok := answer.(*dns.SOA); ok {
256249
soa = soaRR.Hdr.Name
257-
break
250+
}
251+
}
252+
if soa == "" {
253+
for _, ns := range soaResponse.Ns {
254+
if soaRR, ok := ns.(*dns.SOA); ok {
255+
soa = soaRR.Hdr.Name
256+
break
257+
}
258258
}
259259
}
260260
}
261-
nsList, err := net.LookupNS(soa)
262-
if err != nil {
263-
slog.Error("NS lookup failed", "domain", td.Name, "soa", soa, "error", err)
264-
return
265-
}
261+
262+
// Get authoritative nameservers for the domain using the SOA record. If we couldn't get an SOA, we'll just end up with an empty list of nameservers.
266263
var nameservers []string
267-
for _, ns := range nsList {
268-
nameservers = append(nameservers, ns.Host)
264+
if soa != "" {
265+
nsList, err := net.LookupNS(soa)
266+
if err != nil {
267+
slog.Error("NS lookup failed", "domain", td.Name, "soa", soa, "error", err)
268+
return
269+
}
270+
for _, ns := range nsList {
271+
nameservers = append(nameservers, ns.Host)
272+
}
273+
sort.Strings(nameservers)
269274
}
270-
sort.Strings(nameservers)
271275
domain := Domain{
272276
Name: td.Name,
273277
Rank: td.Rank,

0 commit comments

Comments
 (0)