ipwho

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package ipwho is the library behind the ipwho command line: the HTTP client, request shaping, and the typed data models for ipwho.is.

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load.

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "ipwho/dev (+https://github.com/tamnd/ipwho-cli)"

DefaultUserAgent identifies the client to ipwho.is.

View Source
const Host = "ipwho.is"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to ipwho.is over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults: a 30s timeout, a 200ms minimum gap between requests, and five retries on transient errors.

func (*Client) Lookup

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

Lookup fetches geolocation info for the given IP address. If ip is empty, the API returns info for your own IP.

func (*Client) LookupURL

func (c *Client) LookupURL(ctx context.Context, url string) (*IPInfo, error)

LookupURL fetches geolocation info from an explicit URL. It is primarily used in tests to point the client at a mock server.

func (*Client) Self

func (c *Client) Self(ctx context.Context) (*IPInfo, error)

Self fetches geolocation info for your own IP address.

type Connection

type Connection struct {
	ASN    int    `json:"asn"`
	Org    string `json:"org"`
	ISP    string `json:"isp"`
	Domain string `json:"domain"`
}

Connection holds the ASN and organization details for an IP.

type Domain

type Domain struct{}

Domain is the ipwho driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (type, id). An input that looks like an IP address (contains dots or colons with digits) is classified as "ip"; anything else is treated as a search query.

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type IPInfo

type IPInfo struct {
	IP          string     `kit:"id" json:"ip"`
	Type        string     `json:"type"`
	Continent   string     `json:"continent"`
	Country     string     `json:"country"`
	CountryCode string     `json:"country_code"`
	Region      string     `json:"region"`
	RegionCode  string     `json:"region_code"`
	City        string     `json:"city"`
	Postal      string     `json:"postal"`
	Latitude    float64    `json:"latitude"`
	Longitude   float64    `json:"longitude"`
	IsEU        bool       `json:"is_eu"`
	CallingCode string     `json:"calling_code"`
	Capital     string     `json:"capital"`
	Connection  Connection `json:"connection"`
	Timezone    Timezone   `json:"timezone"`
}

IPInfo is the full geolocation record for an IP address.

type Timezone

type Timezone struct {
	ID           string `json:"id"`
	Abbreviation string `json:"abbr"`
	IsDST        bool   `json:"is_dst"`
	UTCOffset    string `json:"utc"`
	CurrentTime  string `json:"current_time"`
}

Timezone holds timezone details for an IP's location.

Jump to

Keyboard shortcuts

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