File: spf-check.go

package info (click to toggle)
golang-blitiri-go-spf 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,524 kB
  • sloc: makefile: 3
file content (65 lines) | stat: -rw-r--r-- 1,330 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//go:build ignore
// +build ignore

// Command line tool to perform SPF checks.
//
// For development and experimentation only.
// No backwards compatibility guarantees.
package main

import (
	"context"
	"flag"
	"fmt"
	"net"
	"os"

	"blitiri.com.ar/go/spf"
)

var (
	debug   = flag.Bool("debug", false, "include debugging output")
	dnsAddr = flag.String("dns_addr", "", "address of the DNS server to use")
)

func main() {
	flag.Usage = func() {
		fmt.Printf("Usage: spf-check [options] 1.2.3.4 name@sender.com\n\n")
		flag.PrintDefaults()
	}

	flag.Parse()
	args := flag.Args()
	if len(args) < 2 {
		flag.Usage()
		os.Exit(1)
	}

	opts := []spf.Option{}
	if *debug {
		traceF := func(f string, a ...interface{}) {
			fmt.Printf("debug: "+f+"\n", a...)
		}
		opts = append(opts, spf.WithTraceFunc(traceF))
	}

	if *dnsAddr != "" {
		dialFunc := func(ctx context.Context, network, addr string) (net.Conn, error) {
			return (&net.Dialer{}).DialContext(ctx, network, *dnsAddr)
		}
		opts = append(opts, spf.WithResolver(
			&net.Resolver{
				PreferGo: true,
				Dial:     dialFunc,
			}))
	}

	ip := net.ParseIP(args[0])
	sender := args[1]
	fmt.Printf("Sender: %v\n", sender)
	fmt.Printf("IP: %v\n", ip)

	r, err := spf.CheckHostWithSender(ip, "", sender, opts...)
	fmt.Printf("Result: %v\n", r)
	fmt.Printf("Error: %v\n", err)
}