64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
|
/*
|
||
|
example is a short example program showing the detailed result from a lookup.
|
||
|
*/
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"net"
|
||
|
"os"
|
||
|
|
||
|
"src.lwithers.me.uk/go/dnsxl"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
xlist *dnsxl.XList
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
if len(os.Args) < 2 {
|
||
|
fmt.Fprintln(os.Stderr, "Expecting one or more names/IPs to look up")
|
||
|
os.Exit(1)
|
||
|
}
|
||
|
|
||
|
xlist = dnsxl.New(nil)
|
||
|
xlist.AddServers("sbl.spamhaus.org", "xbl.spamhaus.org", "pbl.spamhaus.org")
|
||
|
|
||
|
for i := 1; i < len(os.Args); i++ {
|
||
|
lookup(os.Args[i])
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func lookup(name string) {
|
||
|
fmt.Printf("==== %s ====\n", name)
|
||
|
ips, err := net.DefaultResolver.LookupIP(context.Background(), "ip", name)
|
||
|
switch {
|
||
|
case err != nil:
|
||
|
fmt.Printf("Failed to look up name: %v\n", err)
|
||
|
return
|
||
|
case len(ips) == 0:
|
||
|
fmt.Println("No addresses found for name")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
for _, ip := range ips {
|
||
|
fmt.Printf("--- %s\n", ip)
|
||
|
res, err := xlist.LookupIP(ip)
|
||
|
if err != nil {
|
||
|
fmt.Printf("Failed to look up IP: %v\n", err)
|
||
|
continue
|
||
|
}
|
||
|
for _, r := range res {
|
||
|
switch {
|
||
|
case r.Error != nil:
|
||
|
fmt.Printf("%s\tError: %v\n", r.Server, r.Error)
|
||
|
case r.InList:
|
||
|
fmt.Printf("%s\tEntry in list (reason: %q)\n", r.Server, r.Reason)
|
||
|
default:
|
||
|
fmt.Printf("%s\tEntry not in list\n", r.Server)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|