1package dnsbl_test
2
3import (
4 "context"
5 "log"
6 "log/slog"
7 "net"
8
9 "github.com/mjl-/mox/dns"
10 "github.com/mjl-/mox/dnsbl"
11)
12
13func ExampleLookup() {
14 ctx := context.Background()
15 resolver := dns.StrictResolver{}
16
17 // Lookup if ip 127.0.0.2 is in spamhaus blocklist at zone sbl.spamhaus.org.
18 status, explanation, err := dnsbl.Lookup(ctx, slog.Default(), resolver, dns.Domain{ASCII: "sbl.spamhaus.org"}, net.ParseIP("127.0.0.2"))
19 if err != nil {
20 log.Fatalf("dnsbl lookup: %v", err)
21 }
22 switch status {
23 case dnsbl.StatusTemperr:
24 log.Printf("dnsbl lookup, temporary dns error: %v", err)
25 case dnsbl.StatusPass:
26 log.Printf("dnsbl lookup, ip not listed")
27 case dnsbl.StatusFail:
28 log.Printf("dnsbl lookup, ip listed: %s", explanation)
29 }
30}
31