netutils

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: Apache-2.0 Imports: 6 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindLoopbackIPv4Interface

func FindLoopbackIPv4Interface() net.Interface

FindLoopbackIPv4Interface finds the IPv4 loopback interface. It's usually the one with the 127.0.0.1 address but you never know what sort of crazy config you can stumble upon.

func FindPublicIPv4

func FindPublicIPv4() (net.IP, error)

FindPublicIPv4 returns the public IPv4 address of the computer. If there's more than one public IP(v4) address the first found is returned. Docker interfaces and interfaces with index > 100 is skipped

func FreeTCPPort

func FreeTCPPort() (int, error)

FreeTCPPort returns a free TCP port by using net.ListenTCP on port :0

func FreeUDPPort

func FreeUDPPort() (int, error)

FreeUDPPort returns a free UDP port by using net.ListenUDP on port :0

func IsLoopbackAddress added in v1.0.3

func IsLoopbackAddress(listenAddress string) bool

IsLoopbackAddress returns true if the listen address (host:port) points at a loopback address. IPv6 addresses aren't supported.

func PortOfHostPort

func PortOfHostPort(hostport string) int

PortOfHostPort returns the port number for the host:port string. If there's an error it will panic -- use with caution.

func RandomLocalEndpoint

func RandomLocalEndpoint() string

RandomLocalEndpoint returns a random endpoint on the loppback interface.

func RandomPublicEndpoint

func RandomPublicEndpoint() string

RandomPublicEndpoint returns a random public endpoint on the host. It will use the first IPv4 address found on the host.

func ServiceHostPort added in v1.0.7

func ServiceHostPort(addr net.Addr) string

ServiceHostPort returns the listener address as a host:port string. If the listener address points at a loopback address it will return the address of the loopback adapter.

Types

This section is empty.

Jump to

Keyboard shortcuts

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