netaddr

package
v0.35.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: GPL-3.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package netaddr parses host and port strings, picks local and outbound IP addresses, builds bind addresses and routes lookups to a custom DNS server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTCPBindAddr

func BuildTCPBindAddr(localIP string) net.Addr

func BuildUDPBindAddr

func BuildUDPBindAddr(localIP string) *net.UDPAddr

func ExtractHost

func ExtractHost(input string) string

ExtractHost returns the host and port of input, a URL or an address, e.g. "[2001:db8::1]:80".

func FormatAddress

func FormatAddress(s string) string

FormatAddress if the s is just a port,return 127.0.0.1:s

func GetOutboundIP

func GetOutboundIP() net.IP

func GetOutboundIPv4

func GetOutboundIPv4() net.IP

func GetOutboundIPv6

func GetOutboundIPv6() net.IP

func GetPorts

func GetPorts(s string) []int

GetPorts format ports str to an int array

func GetServerIp

func GetServerIp(ip string) string

func Host

func Host(s string) string

Host returns the host of s, an address given as "host", "host:port", "[ipv6]" or "[ipv6]:port", without brackets and with any zone kept. A bare IPv6 address such as "2001:db8::1" is a host without a port. The port is not checked. It returns "" for an empty host or an unclosed or trailing bracket, such as "[::1" or "[::1]x".

func IsPublicHost

func IsPublicHost(addr string) bool

func IsZeroIP

func IsZeroIP(ip net.IP) bool

func LocalUDP4IP

func LocalUDP4IP() (net.IP, error)

LocalUDP4IP returns the preferred local IPv4 egress IP.

func LocalUDP6IP

func LocalUDP6IP() (net.IP, error)

LocalUDP6IP returns the preferred local IPv6 egress IP.

func NormalizeIP

func NormalizeIP(ip net.IP) net.IP

func ParseIP

func ParseIP(s string) (netip.Addr, bool)

ParseIP reads an IP address given alone or as host:port, with IPv6 in brackets and a port in 0-65535. A zone and an IPv4-mapped IPv6 form are kept.

func PickEgressIPFor

func PickEgressIPFor(dstIP net.IP) net.IP

func Port

func Port(s string) int

Port returns the port of s, given as for Host, or 0 when s has no port in 1-65535.

func SetCustomDNS

func SetCustomDNS(dnsAddr string)

func SplitAddrAndHost

func SplitAddrAndHost(s string) (addr, host, sni string)

func SplitServerAndPath

func SplitServerAndPath(s string) (server, path string)

Types

This section is empty.

Jump to

Keyboard shortcuts

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