Documentation ¶
Overview ¶
Package inet provides an overview of the available global unicast addresses and IP versions (IPv4/IPv6/DualStack) and the ability to check connectivity to rely decisions upon for your applications internet connections.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Service to resolve IP address against. I have no affiliation with ip.me. DefaultTarget string = "https://ip.me" // UserAgent fake string to use. DefaultUserAgent = "curl/8.11.0-inet" )
Functions ¶
func Connectivity ¶
Connectivity returns boolean values for IPv4 and IPv6 checked state respectively.
true = success false = failure
Example ¶
package main import ( "fmt" "log" "catinello.eu/inet" ) func main() { var ip4, ip6 bool if inet.DualStack() { ip4, ip6 = inet.Connectivity() } else { if inet.HasIPv4() { ip, err := inet.GetIPv4() if err != nil { log.Fatal(err) } if ip.IsGlobalUnicast() { ip4 = true } } if inet.HasIPv6() { ip, err := inet.GetIPv6() if err != nil { log.Fatal(err) } if ip.IsGlobalUnicast() { ip6 = true } } } fmt.Println(ip4, ip6) }
Output: true true
func DualStack ¶
func DualStack() bool
DualStack returns a boolean value. It retursn true, if the system has a global unicast addresses for IPv4 and IPv6.
func GetIPv4 ¶
GetIPv4 returns the retrieved pulbic IP and nil or an occured error.
Example ¶
package main import ( "fmt" "log" "catinello.eu/inet" ) func main() { ip, err := inet.GetIPv4() if err != nil { log.Fatal(err) } fmt.Println(ip.IsGlobalUnicast()) }
Output: true
func GetIPv6 ¶
GetIPv6 returns the retrieved pulbic IP and nil or an occured error.
Example ¶
package main import ( "fmt" "log" "catinello.eu/inet" ) func main() { ip, err := inet.GetIPv6() if err != nil { log.Fatal(err) } fmt.Println(ip.IsGlobalUnicast()) }
Output: true
func HasIPv4 ¶
func HasIPv4() bool
HasIPv4 returns a boolean value as true, if the system has a global unicast IPv4.
Types ¶
Click to show internal directories.
Click to hide internal directories.