greynoise

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 greynoise is the library behind the greynoise command line: the HTTP client, request shaping, and the typed data models for the GreyNoise Community API.

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. Build your endpoint calls and JSON decoding on top of it.

Index

Constants

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

BaseURL is the root every request is built from.

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

DefaultUserAgent identifies the client to GreyNoise. A real, honest User-Agent is both polite and the thing most likely to keep you unblocked.

View Source
const Host = "api.greynoise.io"

Host is the site this client talks to, and the host the URI driver in domain.go claims.

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 the GreyNoise Community API over HTTPS.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults: a 30 s timeout, a 500 ms minimum gap between requests (polite for a free API), and five retries on transient errors.

func (*Client) GetIP

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

GetIP looks up one IP address against the GreyNoise Community API.

  • GET /v3/community/{ip}

func (*Client) GetIPFrom

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

GetIPFrom fetches and decodes an IPInfo from an arbitrary URL. It is exposed so tests can substitute a local httptest server for the real API.

func (*Client) GetRaw

func (c *Client) GetRaw(ctx context.Context, url string) ([]byte, error)

GetRaw fetches url and returns the raw response body. It is exposed so tests can verify pacing and retry behaviour without involving JSON decoding.

type Config

type Config struct {
	UserAgent string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
}

Config holds optional overrides a caller can pass when building a Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for a GreyNoise Community API client.

type Domain

type Domain struct{}

Domain is the greynoise 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). A valid IP address (contains dots and numeric segments) maps to ("ip", ip).

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"`
	Noise          bool   `json:"noise"`
	RIOT           bool   `json:"riot"`
	Classification string `json:"classification"`
	Name           string `json:"name"`
	Link           string `json:"link"`
	LastSeen       string `json:"last_seen"`
	Message        string `json:"message"`
}

IPInfo is the record returned by a GreyNoise Community IP lookup. Fields that are absent in the response (classification, name, link, last_seen) stay as their zero value.

Jump to

Keyboard shortcuts

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