arinbulk

package
v0.0.0-...-6169d9b Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddrToUint32

func AddrToUint32(ip netip.Addr) uint32

AddrToUint32 converts netip.Addr to uint32 (big-endian)

func ExpandNetType

func ExpandNetType(netType string) string

ExpandNetType returns a human-readable description of the net type

func IsValidOrgName

func IsValidOrgName(name string) bool

IsValidOrgName filters out placeholder or administrative org names

func ParseRange

func ParseRange(rangeStr string) (uint32, uint32, error)

ParseRange parses an IP range string like "8.0.0.0 - 8.255.255.255"

func PrefixToRange

func PrefixToRange(prefix string) (uint32, uint32, error)

PrefixToRange converts a CIDR prefix to start/end uint32

func Uint32ToAddr

func Uint32ToAddr(ip uint32) netip.Addr

Uint32ToAddr converts uint32 to netip.Addr (big-endian)

Types

type ARINDatabase

type ARINDatabase struct {
	XMLName xml.Name `xml:"arin"`
	Nets    []NetXML `xml:"net"`
	Orgs    []OrgXML `xml:"org"`
	ASNs    []ASNXML `xml:"asn"`
	POCs    []POCXML `xml:"poc"`
}

type ASNXML

type ASNXML struct {
	Handle     string `xml:"handle"`
	Name       string `xml:"name"`
	StartASN   string `xml:"startAsNumber"`
	EndASN     string `xml:"endAsNumber"`
	OrgHandle  string `xml:"orgHandle"`
	RegDate    string `xml:"registrationDate"`
	UpdateDate string `xml:"updateDate"`
}

type Database

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

Database manages the ARIN bulk data index

func BuildDatabase

func BuildDatabase(path string, nets []NetBlock, orgs map[string]Organization) (*Database, error)

BuildDatabase creates a new ARIN bulk database from parsed data

func BuildDatabaseStreaming

func BuildDatabaseStreaming(path string, r io.Reader) (*Database, error)

BuildDatabaseStreaming creates a new ARIN bulk database with low memory usage by writing organizations immediately and only keeping networks in memory for sorting

func OpenDatabase

func OpenDatabase(path string) (*Database, error)

OpenDatabase opens an existing ARIN bulk database with default cache size

func OpenDatabaseWithCache

func OpenDatabaseWithCache(path string, cacheSize int) (*Database, error)

OpenDatabaseWithCache opens with custom cache size (in bytes)

func (*Database) Close

func (d *Database) Close() error

Close closes the database

func (*Database) GetMetadata

func (d *Database) GetMetadata() (*Metadata, error)

GetMetadata retrieves database metadata

func (*Database) GetOrganization

func (d *Database) GetOrganization(orgID string) (Organization, error)

GetOrganization retrieves an organization by ID

func (*Database) IterateRanges

func (d *Database) IterateRanges(callback func(NetBlock) error) error

IterateRanges iterates over all network ranges

func (*Database) LookupIP

func (d *Database) LookupIP(ip netip.Addr) (*Match, error)

LookupIP finds the most specific network containing the IP

func (*Database) LookupPrefix

func (d *Database) LookupPrefix(prefix netip.Prefix) (*Match, error)

LookupPrefix finds the most specific network that exactly matches or contains the prefix

func (*Database) Stats

func (d *Database) Stats() (netCount, orgCount int64, err error)

Stats returns database statistics

type Error

type Error string

Error types

const (
	ErrNotFound       Error = "no matching network found"
	ErrInvalidIP      Error = "invalid IP address"
	ErrInvalidRange   Error = "invalid IP range"
	ErrParseError     Error = "parse error"
	ErrDatabaseClosed Error = "database is closed"
)

func (Error) Error

func (e Error) Error() string

type Match

type Match struct {
	Start        netip.Addr   // Start IP
	End          netip.Addr   // End IP
	Prefix       netip.Prefix // Query prefix
	NetHandle    string       // ARIN net handle
	OrgID        string       // Organization ID
	OrgName      string       // Organization name
	NetType      string       // Network type
	NetName      string       // Network name
	Country      string       // Country code
	MatchedAt    time.Time    // When lookup was performed
	FullyCovered bool         // True if fully covers query
}

Match represents the result of a lookup

type Metadata

type Metadata struct {
	SchemaVersion int       // Database schema version
	BuildTime     time.Time // When built
	NetBlockCount int64     // Number of net blocks
	OrgCount      int64     // Number of organizations
	SourceDate    string    // Date of ARIN bulk data
	SourceURL     string    // Where data was fetched from
}

Metadata stores build information

type NetBlock

type NetBlock struct {
	Start      uint32   // Start IP (big-endian uint32 for IPv4)
	End        uint32   // End IP (big-endian uint32 for IPv4)
	NetName    string   // Network name
	NetHandle  string   // ARIN net handle (e.g., NET-8-0-0-0-1)
	OrgID      string   // Organization ID (e.g., LPL-141)
	NetType    string   // Direct Allocation, Direct Assignment, etc.
	ParentNet  string   // Parent network handle
	CIDR       []string // CIDR blocks (can be multiple)
	Comments   []string // Comments
	UpdateDate string   // Last updated date
}

NetBlock represents an ARIN network block (NetRange)

func ParseXML

func ParseXML(r io.Reader) ([]NetBlock, map[string]Organization, error)

ParseXML parses the ARIN bulk XML file

type NetBlockXML

type NetBlockXML struct {
	StartAddress string `xml:"startAddress"`
	EndAddress   string `xml:"endAddress"`
	CIDRLength   string `xml:"cidrLength"`
	Type         string `xml:"type"`
	Description  string `xml:"description"`
}

type NetBlocksXML

type NetBlocksXML struct {
	Blocks []NetBlockXML `xml:"netBlock"`
}

type NetXML

type NetXML struct {
	Handle       string       `xml:"handle"`
	Name         string       `xml:"name"`
	OrgHandle    string       `xml:"orgHandle"`
	NetBlocks    NetBlocksXML `xml:"netBlocks"`
	ParentHandle string       `xml:"parentNetHandle"`
	RegDate      string       `xml:"registrationDate"`
	UpdateDate   string       `xml:"updateDate"`
	Version      string       `xml:"version"` // "4" or "6"
	Comments     []string     `xml:"comment>line"`
}

type OrgXML

type OrgXML struct {
	Handle     string `xml:"handle"`
	Name       string `xml:"name"`
	ISO3166_1  string `xml:"iso3166-1>code2"` // Country
	ISO3166_2  string `xml:"iso3166-2>code3"` // State/Province
	RegDate    string `xml:"registrationDate"`
	UpdateDate string `xml:"updateDate"`
}

type Organization

type Organization struct {
	OrgID      string // Organization ID (e.g., LPL-141)
	OrgName    string // Organization name
	Address    string // Street address
	City       string
	StateProv  string // State/Province
	PostalCode string
	Country    string
	UpdateDate string
}

Organization represents an ARIN organization

type POCXML

type POCXML struct {
	Handle  string `xml:"handle"`
	Name    string `xml:"contactName"`
	Company string `xml:"companyName"`
}

Jump to

Keyboard shortcuts

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