feat: Add support for reverse DNS lookups
Closes https://github.com/mr-karan/doggo/issues/25
This commit is contained in:
parent
e5acf1214c
commit
9e3656fae9
5 changed files with 36 additions and 3 deletions
|
@ -33,3 +33,23 @@ func (app *App) PrepareQuestions() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ReverseLookup is used to perform a reverse DNS Lookup
|
||||
// using an IPv4 or IPv6 address.
|
||||
// Query Type is set to PTR, Query Class is set to IN.
|
||||
// Query Names must be formatted in in-addr.arpa. or ip6.arpa format.
|
||||
func (app *App) ReverseLookup() {
|
||||
app.QueryFlags.QTypes = []string{"PTR"}
|
||||
app.QueryFlags.QClasses = []string{"IN"}
|
||||
formattedNames := make([]string, 0, len(app.QueryFlags.QNames))
|
||||
|
||||
for _, n := range app.QueryFlags.QNames {
|
||||
addr, err := dns.ReverseAddr(n)
|
||||
if err != nil {
|
||||
app.Logger.WithError(err).Error("error formatting address")
|
||||
app.Logger.Exit(2)
|
||||
}
|
||||
formattedNames = append(formattedNames, addr)
|
||||
}
|
||||
app.QueryFlags.QNames = formattedNames
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue