Documentation ¶
Overview ¶
Package pubip gets your public IP address from several services
Index ¶
Constants ¶
View Source
const MaxTries = 3
MaxTries is the maximum amount of tries to attempt to one service.
View Source
const Version = "1.0.0"
Version indicates the version of this package.
Variables ¶
View Source
var APIURIs = []string{
"https://api.ipify.org",
"http://myexternalip.com/raw",
"http://ipinfo.io/ip",
"http://ipecho.net/plain",
"http://icanhazip.com",
"http://ifconfig.me/ip",
"http://ident.me",
"http://checkip.amazonaws.com",
"http://bot.whatismyipaddress.com",
"http://whatismyip.akamai.com",
"http://wgetip.com",
"http://ip.appspot.com",
"http://ip.tyk.nu",
"https://shtuff.it/myip/short",
}
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 ¶
Get queries several APIs to retrieve a `net.IP` of this machine's public IP address.
Usage:
package main import ( "fmt" "github.com/chyeh/pubip" ) func main() { ip, err := pubip.Get() if err != nil { fmt.Println("Couldn't get my IP address:", err) } else { fmt.Println("My IP address is:", ip) } }
func GetIPBy ¶
GetIPBy queries an API to retrieve a `net.IP` of this machine's public IP address.
Usage:
package main import ( "fmt" "github.com/chyeh/pubip" ) func main() { ip, err := pubip.GetIPBy("https://api.ipify.org") if err != nil { fmt.Println("Couldn't get my IP address:", err) } else { fmt.Println("My IP address is:", ip) } }
func GetIPStrBy ¶
GetIPStrBy queries an API to retrieve a `string` of this machine's public IP address.
Usage:
package main import ( "fmt" "github.com/chyeh/pubip" ) func main() { ip, err := pubip.GetIPBy("https://api.ipify.org") if err != nil { fmt.Println("Couldn't get my IP address:", err) } else { fmt.Println("My IP address is:", ip) } }
func GetStr ¶
GetStr queries several APIs to retrieve a `string` of this machine's public IP address.
Usage:
package main import ( "fmt" "github.com/chyeh/pubip" ) func main() { ip, err := pubip.Get() if err != nil { fmt.Println("Couldn't get my IP address:", err) } else { fmt.Println("My IP address is:", ip) } }
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.