zmap / zdns

Fast DNS Lookup Library and CLI Tool
Apache License 2.0
939 stars 123 forks source link

Pass domains as NameServers and NameServer struct re-factor #435

Closed phillip-stephens closed 2 months ago

phillip-stephens commented 2 months ago

Description

95% of the changes here introduce a new NameServer struct:

type NameServer struct {
    IP         net.IP // ip address, required
    Port       uint16 // udp/tcp port
    DomainName string // used for SNI with TLS, required if you want to validate server certs
}

This lets us have a bit more type safety than we had before with passing an arbitrary string as a nameServer into functions.

Additionally, though, this adds the ability to specify nameservers by domain, ex: ./zdns A google.com --name-servers="one.one.one.one". In this case, we'll query for the IPs (A and AAAA) and discard A if we're doing --6 or AAAA if --4, and store these as our resolver.NameServers.

Finally, if a user is passing nameservers as domains in as input on a per-line basis:

yahoo.com,one.one.one.one
google.com,8.8.8.8

We'll choose a random IP from one.one.one.one's records and use that to query.

Testing

Added a few unit tests and integration tests to test the new functionality.