asndb

package module
v0.0.0-...-6576d0e Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2022 License: 0BSD Imports: 9 Imported by: 0

README

ASNDB

This is a package that provides an interface to iptoasn's database.

This is meant to work with ip2asn-combined.tsv dataset, it will also work with the IPv4 and IPv6 only datasets.

This package uses net/netip.

See godoc for more reference.

ASList

ASList facilitates looking up AS zone by IP address using Find(ip).

And viewing neighbour AS zones by Index(ip) and FromIndex(index).

ASNMap

ASNMap facilitates looking up AS zones by ASN using ListAS(asn).

And listing all ASN by ListASN()

Documentation

Overview

Package asndb implement asn lookup and data handling. This library will handle tsv data sourced from https://iptoasn.com.

The data can be downloaded via DownloadFromURL(DownloadViaIpToAsn), which then parsed using LoadFromTSV(), that can be used to initiate a ASList or ASNMap.

Index

Constants

View Source
const DownloadViaIpToAsn = "https://iptoasn.com/data/ip2asn-combined.tsv.gz"

Variables

This section is empty.

Functions

func DownloadFromURL

func DownloadFromURL(url string) (io.ReadCloser, error)

Types

type AS

type AS struct {
	StartIP       netip.Addr
	EndIP         netip.Addr
	ASNumber      int
	CountryCode   string
	ASDescription string
}

AS contains information about an AS zone belonging to an ASNumber. the StartIP and EndIP denotes a range that belongs to the AS.

func LoadFromTSV

func LoadFromTSV(reader io.Reader) ([]AS, error)

func (AS) Contains

func (a AS) Contains(ip netip.Addr) bool

Contains checks if an ip is part of this AS zone.

func (AS) String

func (a AS) String() string

String returns a string representation of the AS.

type ASList

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

ASList holds a list of AS zones.

func NewASList

func NewASList(s []AS) *ASList

NewASList creates a new registry from the given list of AS zones. The given slice will be cloned and sorted by StartIP.

func (*ASList) Find

func (r *ASList) Find(ip netip.Addr) (AS, bool)

Find finds and returns the AS zone for a given IP address. Bool indicates if AS is valid and found Notice: if multiple zones claims an IP, the closest AS zone gets returned.

func (*ASList) FindList

func (r *ASList) FindList(ip netip.Addr, search uint) []AS

FindList attempts to find and return neighbouring AS that contain given ip address. search dictate how many invalid AS zones to skip before returning. This method is only useful when an IP has been claimed by multiple AS zones.

func (*ASList) FromIndex

func (r *ASList) FromIndex(i int) (AS, bool)

FromIndex returns an AS zone at a given index. Returns false if the index is out of bounds.

func (*ASList) Index

func (r *ASList) Index(ip netip.Addr) int

Index returns an index closest to AS zone for a given IP address. Does not guarantee the AS of said index contains the IP. If the index is out of bounds, it returns -1.

func (*ASList) IndexLen

func (r *ASList) IndexLen() int

IndexLen returns the length of the AS zone.

type ASNMap

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

func NewASNMap

func NewASNMap(s []AS) *ASNMap

func (*ASNMap) ListAS

func (m *ASNMap) ListAS(asn int) ([]AS, bool)

ListAS returns a list of AS zones controlled by given asn. The returned slice will be cloned and can be freely edited.

func (*ASNMap) ListASN

func (m *ASNMap) ListASN() []AS

ListASN returns a list of ASN. Behaviour of AS's details are undefined if details are inconsistent. AS.StartIP and AS.EndIP will not be defined.

Jump to

Keyboard shortcuts

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