enrich

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package enrich performs lightweight per-row enrichment of probe results: reverse-DNS lookups today, ASN / org / location later.

The DNS resolver routes lookups through user-configured servers so that pingtrace can decode hostnames in private networks (split- horizon DNS) as well as on the public internet.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPrivateIP

func IsPrivateIP(ip string) bool

IsPrivateIP reports whether ip falls in any of the RFC1918, loopback, link-local, ULA, or CGNAT ranges.

func ParseList

func ParseList(s string) []string

ParseList splits a comma- or whitespace-separated string into a trimmed slice. Empty entries are dropped.

Types

type IPInfo

type IPInfo struct {
	IP       string
	Hostname string
	City     string
	Region   string
	Country  string
	Org      string // human-readable org name (AS prefix stripped)
	ASN      string // e.g. "AS13335"
	Loc      string // "lat,lon"
}

IPInfo is the subset of ipinfo.io fields pingtrace surfaces.

func (IPInfo) FormatLocation

func (i IPInfo) FormatLocation() string

FormatLocation builds a compact "City, CC" string for the location column. Falls back to lat,lon when city is unset.

type IPInfoClient

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

IPInfoClient looks up IP metadata via ipinfo.io and caches the result per IP. Safe for concurrent use.

func NewIPInfo

func NewIPInfo(token string, timeout time.Duration) *IPInfoClient

NewIPInfo builds a client. token may be empty (Enabled() will then return false and Lookup() short-circuits to an empty result).

func (*IPInfoClient) Enabled

func (c *IPInfoClient) Enabled() bool

Enabled reports whether a token is configured.

func (*IPInfoClient) Lookup

func (c *IPInfoClient) Lookup(ctx context.Context, ip string) IPInfo

Lookup fetches IPInfo for ip. Returns a zero IPInfo (no error signal) when disabled, on private IPs, on HTTP errors, or on timeout - pingtrace prefers showing blank cells to surfacing transient enrichment failures.

type PeeringDBClient

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

PeeringDBClient fetches /api/net records keyed by ASN.

func NewPeeringDB

func NewPeeringDB(token string, timeout time.Duration) *PeeringDBClient

NewPeeringDB builds a client. token may be empty - PeeringDB allows anonymous reads with a lower rate limit. Enabled() is always true so the client is used whenever an ASN is known.

func (*PeeringDBClient) Enabled

func (c *PeeringDBClient) Enabled() bool

Enabled reports whether this client should be used. Returns true even without a token (anonymous reads work, just rate-limited). Callers should still guard on whether they have an ASN to query.

func (*PeeringDBClient) LookupASN

func (c *PeeringDBClient) LookupASN(ctx context.Context, asn string) PeeringDBInfo

LookupASN parses "AS13335" or "13335" and fetches the matching net record. Returns a zero PeeringDBInfo on any failure (no network, bad asn, http error, empty result).

type PeeringDBInfo

type PeeringDBInfo struct {
	ASN       int
	Name      string
	NetType   string // Content / NSP / Cable/DSL/ISP / Enterprise / Educational
	Policy    string // Open / Selective / Restrictive / No
	Traffic   string // e.g. "100+ Gbps"
	Prefixes4 int
	Prefixes6 int
	IXPCount  int
}

PeeringDBInfo is the subset of PeeringDB net record fields surfaced by pingtrace.

type Resolver

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

Resolver performs reverse-DNS lookups against caller-supplied public and private servers. It is safe for concurrent use.

func New

func New(publicSrv, privateSrv []string, timeout time.Duration) *Resolver

New builds a Resolver. publicSrv and privateSrv are lists of host[:port] entries; port defaults to 53. timeout is the per- lookup wall-clock budget. Either list may be empty; if both are empty, Lookup* return "" immediately so callers pay no cost.

func (*Resolver) Enabled

func (r *Resolver) Enabled() bool

Enabled reports whether the resolver has at least one server configured. When false, all lookups short-circuit to "".

func (*Resolver) Lookup

func (r *Resolver) Lookup(ctx context.Context, ip string) string

Lookup auto-routes by IP class: private IPs go to the private server list, public IPs go to the public server list. Returns "" when no applicable servers are configured or the lookup fails. This is the convenient entry point for callers that want a single "decoded hostname" string per row.

func (*Resolver) LookupPrivate

func (r *Resolver) LookupPrivate(ctx context.Context, ip string) string

LookupPrivate resolves ip via the private server list. Returns "" when no private servers are configured, when ip is not a private address, or when the lookup fails.

func (*Resolver) LookupPublic

func (r *Resolver) LookupPublic(ctx context.Context, ip string) string

LookupPublic resolves ip via the public server list. Returns "" when no public servers are configured, when ip is not a routable address, or when the lookup fails / times out.

func (*Resolver) PrivateEnabled added in v1.0.1

func (r *Resolver) PrivateEnabled() bool

PrivateEnabled reports whether at least one private DNS server is configured.

func (*Resolver) PublicEnabled added in v1.0.1

func (r *Resolver) PublicEnabled() bool

PublicEnabled reports whether at least one public DNS server is configured.

Jump to

Keyboard shortcuts

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