myip

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

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

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

README

myip

Small utility to find one's IP. Can also be used a as library! Get it from the github releases or build it yourself with

go clone https://github.com/wnke/myip
cd myip
go build -o myip ./cmd
cp myip $HOME/.local/bin/myip

Usage

Command line
$ myip
123.123.111.111
Library
import 	"github.com/wnke/myip"

//...
ipa, err := myip.NewIPDiscover()
if err != nil {
    return err
}

ip, err := ipa.Discover()
if err != nil {
    return err
}
fmt.Print(ip.String())

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyProviders = errors.New("provider list is empty")
	ErrInvalidURL     = errors.New("invalid URL")

	ErrNoResponse      = errors.New("failed to get response from provider")
	ErrStatusCode      = errors.New("provider returned a non OK status code")
	ErrInvalidResponse = errors.New("failed to read IP from provider")
	ErrParseResponse   = errors.New("failed to parse IP from provider")
)
View Source
var DEFAULT_PROVIDERS = []string{
	"https://checkip.amazonaws.com",
	"https://ipconfig.io",
	"https://icanhazip.com",
	"https://ifconfig.me",
}

Functions

This section is empty.

Types

type IPDiscover

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

func NewIPDiscover

func NewIPDiscover() (*IPDiscover, error)

func NewIPDiscoverWithProviders

func NewIPDiscoverWithProviders(providers []string) (*IPDiscover, error)

func (*IPDiscover) Discover

func (ipd *IPDiscover) Discover() (*netip.Addr, error)

func (*IPDiscover) Providers

func (ipd *IPDiscover) Providers() []string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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