spf2ip

package module
v0.0.0-...-7dad53a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2025 License: MIT Imports: 12 Imported by: 0

README

SPF2IP-Go

A Go implementation designed to resolve a domain's SPF (Sender Policy Framework) records into a list of IP addresses and CIDR blocks. This project is a remake of and inspired by the original Python-based SPF2IP by Nathan Dines.

This tool recursively processes SPF records, handling include and redirect mechanisms, and extracts all authorized IP networks.

Features

  • Resolves SPF records for a given domain.
  • Supports both IPv4 and IPv6 resolution (ip4, ip6, a, mx mechanisms).
  • Handles include and redirect mechanisms recursively.
  • Implements strict redirect logic (a redirect overrides preceding mechanisms in the same record).
  • Detects and prevents resolution loops and excessive lookups (via include depth limit).
  • Outputs all IPs and networks in canonical CIDR notation (e.g., 1.2.3.4/32, 10.0.0.0/24), sorted and unique.

Acknowledgements

This project is a Go remake of the original SPF2IP (Python) by Nathan Dines. Full credit and thanks to Nathan Dines for the original concept and implementation.

Installation

Building from Source

To build the spf2ip-go executable from source, follow these steps:

  1. Clone the repository:

    git clone https://github.com/HENNGE/spf2ip-go.git
    cd spf2ip-go
    
  2. Build the executable:

    go build github.com/HENNGE/spf2ip-go/cmd/spf2ip-go
    

    This will create an executable named spf2ip-go in the current directory.

Using Go Modules

If you prefer to use Go modules, you can run the following command to install the package:

go install github.com/HENNGE/spf2ip-go/cmd/spf2ip-go@latest

CLI Usage

spf2ip-go --domain <domain_name> [--ip-version <4|6>] [--debug]
Flags
  • --domain <string>: (Required) The domain for which the SPF records should be resolved.
  • --ip-version <int>: (Optional) The IP version to extract. Accepts 4 for IPv4 or 6 for IPv6. Defaults to 4.
  • --debug: (Optional) Enable debug logging output to stderr. Defaults to false.
Examples
  1. Get IPv4 addresses for example.com:

    spf2ip-go --domain example.com
    
  2. Get IPv6 addresses for example.com:

    spf2ip-go --domain example.com --ip-version 6
    
  3. Get IPv4 addresses for example.com with debug output:

    spf2ip-go --domain example.com --debug
    

Documentation

Overview

Code generated by MockGen. DO NOT EDIT. Source: spf2ip.go

Generated by this command:

mockgen -package spf2ip -source spf2ip.go -destination netresolver_mock.go

Package spf2ip is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidIPVersion = errors.New("spf2ip: invalid IP version specified, must be 4 or 6")
	ErrLoopDetected     = errors.New("spf2ip: loop detected in SPF resolution")
	ErrExceededMaxDepth = errors.New("spf2ip: maximum SPF include depth exceeded")
)

Functions

This section is empty.

Types

type MockNetResolver

type MockNetResolver struct {
	// contains filtered or unexported fields
}

MockNetResolver is a mock of NetResolver interface.

func NewMockNetResolver

func NewMockNetResolver(ctrl *gomock.Controller) *MockNetResolver

NewMockNetResolver creates a new mock instance.

func (*MockNetResolver) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockNetResolver) LookupIP

func (m *MockNetResolver) LookupIP(ctx context.Context, network, host string) ([]net.IP, error)

LookupIP mocks base method.

func (*MockNetResolver) LookupMX

func (m *MockNetResolver) LookupMX(ctx context.Context, domain string) ([]*net.MX, error)

LookupMX mocks base method.

func (*MockNetResolver) LookupTXT

func (m *MockNetResolver) LookupTXT(ctx context.Context, domain string) ([]string, error)

LookupTXT mocks base method.

type MockNetResolverMockRecorder

type MockNetResolverMockRecorder struct {
	// contains filtered or unexported fields
}

MockNetResolverMockRecorder is the mock recorder for MockNetResolver.

func (*MockNetResolverMockRecorder) LookupIP

func (mr *MockNetResolverMockRecorder) LookupIP(ctx, network, host any) *gomock.Call

LookupIP indicates an expected call of LookupIP.

func (*MockNetResolverMockRecorder) LookupMX

func (mr *MockNetResolverMockRecorder) LookupMX(ctx, domain any) *gomock.Call

LookupMX indicates an expected call of LookupMX.

func (*MockNetResolverMockRecorder) LookupTXT

func (mr *MockNetResolverMockRecorder) LookupTXT(ctx, domain any) *gomock.Call

LookupTXT indicates an expected call of LookupTXT.

type NetResolver

type NetResolver interface {
	LookupIP(ctx context.Context, network, host string) ([]net.IP, error)
	LookupMX(ctx context.Context, domain string) ([]*net.MX, error)
	LookupTXT(ctx context.Context, domain string) ([]string, error)
}

type SPF2IPResolver

type SPF2IPResolver struct {
	// contains filtered or unexported fields
}

func NewSPF2IPResolver

func NewSPF2IPResolver(netResolver NetResolver, debugLogging bool) *SPF2IPResolver

func (*SPF2IPResolver) Resolve

func (r *SPF2IPResolver) Resolve(ctx context.Context, domain string, ipVersion int) ([]string, error)

Directories

Path Synopsis
cmd
spf2ip-go command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL