Initial working version, with example.
This commit is contained in:
parent
307d0b2a94
commit
15b34b43ad
9 changed files with 350 additions and 5 deletions
63
cmd/example/example.go
Normal file
63
cmd/example/example.go
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue