pubip

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: LGPL-3.0 Imports: 10 Imported by: 0

README

pubip

A simple package for getting your public IP address by several services. It's inspired by https://github.com/chyeh/pubip.

Pubip validates the results from several services and returns the IP address if a valid one is found. Based on the assumption that the services your program depends on are not always available, it's better to have more backups services. This package gives you the public IP address from several different APIs.

Documentation

Index

Constants

View Source
const MaxTries = 3

MaxTries is the maximum amount of tries to attempt to one service.

Variables

View Source
var APIURIs = []string{
	"https://api.ipify.org",
	"http://ipinfo.io/ip",
	"http://checkip.amazonaws.com",
	"http://whatismyip.akamai.com",
	"http://ipv4.text.wtfismyip.com",
}

APIURIs is the URIs of the services.

View Source
var Timeout = 2 * time.Second

Timeout sets the time limit of collecting results from different services.

Functions

func Get

func Get() (net.IP, error)

Get queries several APIs to retrieve a `net.IP` of this machine's public IP address.

func GetIPBy

func GetIPBy(dest string) (net.IP, error)

GetIPBy queries an API to retrieve a `net.IP` of this machine's public IP address.

Types

This section is empty.

Jump to

Keyboard shortcuts

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