public

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

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

Go to latest
Published: Nov 26, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package public provides functions to determine your systems internet connectivity (IPv4/IPv6) and retrieve the respectively used public IP.

It uses a public service to work independently from your infrastructure. Beware! Online service: https://ip.me

You can easily replace this by changing the global variable DefaultTarget.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// Service to resolve IP address against.
	DefaultTarget string = "https://ip.me"

	// UserAgent string to use.
	DefaultUserAgent = "curl/7.84.0"
)

Functions

func IPv4

func IPv4() (net.IP, error)

IPv4 returns your IPv4 address.

Example
package main

import (
	"fmt"
	"log"

	"catinello.eu/public"
)

func main() {
	ip, err := public.IPv4()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(ip.IsGlobalUnicast())
}
Output:

true

func IPv6

func IPv6() (net.IP, error)

IPv6 returns your IPv6 address.

Example
package main

import (
	"fmt"
	"log"

	"catinello.eu/public"
)

func main() {
	ip, err := public.IPv6()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(ip.IsGlobalUnicast())
}
Output:

true

Types

This section is empty.

Jump to

Keyboard shortcuts

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