clouddetect

package module
v0.0.0-...-f11dd17 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2018 License: MIT Imports: 9 Imported by: 3

README

clouddetect

Go Report Card

Go package to determine if an IP address resolves to one of the major cloud providers. Helpful for risk-scoring potential bot traffic in conjunction with other signals such as User Agent.

Currently the library consumes the published IP ranges from Amazon, Google, and Microsoft.

API usage

package main

import (
	"fmt"
	"os"

	"github.com/99designs/clouddetect"
)

func main() {
    ip := net.ParseIP("127.0.0.1")
    if cloud, err := clouddetect.Resolve(ip); err == nil {
        fmt.Println(cloud.ProviderName)
    }
}

The default Client has an internal cache with a TTL of 12 hours. The first request to resolve an IP will be slow as it fetches all published ranges. See the clouddetect godocs for more detail on the API.

CLI usage

go get github.com/99designs/clouddetect/cli/clouddetect

then

clouddetect -ip=127.0.0.1

LICENSE

MIT 2018 99designs

Documentation

Index

Constants

View Source
const (
	// ProviderAmazon is AWS
	ProviderAmazon = "Amazon Web Services"
	// ProviderGoogle is Google Cloud
	ProviderGoogle = "Google Cloud"
	// ProviderMicrosoft is Microsoft Azure
	ProviderMicrosoft = "Microsoft Azure"
)

Variables

View Source
var (
	// ErrNotCloudIP is error returned when IP does not match any of the published list of ranges
	ErrNotCloudIP = errors.New("not resolved to any known cloud IP range")
)

Functions

This section is empty.

Types

type Client

type Client struct {

	// Time to keep IP ranges cached for (default 12 hours)
	TTL time.Duration
	// contains filtered or unexported fields
}

Client will eventually hold cache of IP ranges

func DefaultClient

func DefaultClient() *Client

DefaultClient is the default Client for resolving requests

func NewClient

func NewClient(TTL time.Duration) *Client

NewClient generates a Client with specified cache TTL

func (*Client) Resolve

func (c *Client) Resolve(ip net.IP) (*Response, error)

Resolve will take the given ip and determine if it exists within any of the major cloud providers' published IP ranges and any extra metadata that may be of use. It returns ErrNotCloudIP if the IP does not resolve against any lists

type Response

type Response struct {
	ProviderName string
	Region       string
	Subnet       *net.IPNet
}

Response provides details of the cloud environment the IP resolved to

func Resolve

func Resolve(ip net.IP) (*Response, error)

Resolve is a convenience function to resolve an IP against the DefaultClient

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

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