ipisp

package
v0.2.89 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: BSD-3-Clause, MIT Imports: 9 Imported by: 0

README

ipisp

GoDoc

ipisp provides a Go client for Team Cymru's IP-ASN mapping service. Basically, this library allows you to query an IP address' ISP and allocation information.

go get github.com/ammario/ipisp/v2

Features

  • 0 external dependencies
  • Bulk and single lookups
  • Query ISP name, ASN, country, registry and CIDR range

Basic usage

Running

resp, err := ipisp.LookupIP(context.Background(), net.ParseIP("4.2.2.2"))
if err != nil {
    log.Fatalf("lookup: %v", err)
}
fmt.Printf("ISP: %s\n", resp.ISPName)

displays

ISP: LEVEL3, US

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnexpectedTokens = errors.New("an unexpect token was received while reading response")
)

Functions

This section is empty.

Types

type ASN

type ASN int

ASN represents an Autonomous Systems Number. See https://en.wikipedia.org/wiki/Autonomous_system_(Internet).

func ParseASN

func ParseASN(asn string) (ASN, error)

ParseASN parses a string like `AS2341` into ASN `2341`.

func (ASN) String

func (a ASN) String() string

String represents an ASN like `5544“ as `AS5544`.`

type BulkClient

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

BulkClient uses the WHOIS service to conduct bulk lookups.

func DialBulkClient

func DialBulkClient(ctx context.Context) (*BulkClient, error)

DialBulkClient returns a connected WHOIS client. This client should be used for bulk lookups.

func (*BulkClient) Close

func (c *BulkClient) Close() error

func (*BulkClient) LookupASNs

func (c *BulkClient) LookupASNs(asns ...ASN) ([]Response, error)

LookupASNs looks up ASNs. Response IP and Range fields are zeroed

func (*BulkClient) LookupIPs

func (c *BulkClient) LookupIPs(ips ...net.IP) ([]Response, error)

type Response

type Response struct {
	IP          net.IP
	ASN         ASN
	ISPName     string
	Country     string
	Registry    string
	Range       *net.IPNet
	AllocatedAt time.Time
}

Response contains a response from Cymru.

func LookupASN

func LookupASN(ctx context.Context, asn ASN) (*Response, error)

func LookupIP

func LookupIP(ctx context.Context, ip net.IP) (*Response, error)

LookupIP looks up a single IP with the API. The service recommends that bulk lookups use the BulkClient out of respect for their server load.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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