Documentation
¶
Overview ¶
Package network provides utility functions to extract some data about network
Index ¶
- Constants
- Variables
- func AddrEqual(a, b string) bool
- func BroadcastFromPrefix(prefix netip.Prefix) (netip.Addr, error)
- func DisplayInterfaces(includeAny bool) error
- func GetDefaultGatewayIPv4() (netip.Addr, error)
- func GetDefaultGatewayIPv4FromRoute() (netip.Addr, error)
- func GetDefaultGatewayIPv6() (netip.Addr, error)
- func GetDefaultGatewayIPv6FromRoute() (netip.Addr, error)
- func GetDefaultInterface() (*net.Interface, error)
- func GetDefaultInterfaceFromRoute() (*net.Interface, error)
- func GetDefaultInterfaceFromRouteIPv6() (*net.Interface, error)
- func GetGatewayIPv4FromInterface(iface string) (netip.Addr, error)
- func GetGatewayIPv6FromInterface(iface string) (netip.Addr, error)
- func GetHostIPv6GlobalUnicastFromRoute() (netip.Addr, error)
- func GetHostName(ip netip.Addr) (string, error)
- func GetIPv4PrefixFromInterface(iface *net.Interface) (netip.Prefix, error)
- func GetIPv6GlobalUnicastPrefixFromInterface(iface *net.Interface) (netip.Prefix, error)
- func GetIPv6LinkLocalUnicastPrefixFromInterface(iface *net.Interface) (netip.Prefix, error)
- func GetIPv6Resolver(dev *net.Interface) *net.UDPAddr
- func GetPromiscuous(iface string) int
- func GetSystemNameservers() ([]netip.Addr, error)
- func InterfaceByName(name string) (*net.Interface, error)
- func Is6(ip netip.Addr) bool
- func IsLocalAddress(addr string) bool
- func ListenPacket(conf *ListenConfig) (*packet.Conn, error)
- func ParseAddrPort(v, defaultHost string) (netip.AddrPort, error)
- func PrefixIsValid(prefix netip.Addr, length int) bool
- func PrettifyBytes(b int64) string
- func SetPromiscuous(iface string, enable bool) error
- func StripZone(ip netip.Addr) netip.Addr
- type ListenConfig
Constants ¶
const ETH_P_ALL int = 0x03
Variables ¶
var ( BroadcastMAC = net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff} LoopbackMAC = net.HardwareAddr{0x00, 0x00, 0x00, 0x00, 0x00, 0x00} IPv6MulticastMAC = net.HardwareAddr{0x33, 0x33, 0x00, 0x00, 0x00, 0x01} IPv6MulticastAllNodes = netip.MustParseAddr("ff02::1") IPv6MulticastAllRouters = netip.MustParseAddr("ff02::2") )
Functions ¶
func AddrEqual ¶ added in v0.0.13
AddrEqual compares two address strings and returns true if they are equal.
It treats loopback and unspecified IPs as equivalent. Returns false in case of inequality or error.
func BroadcastFromPrefix ¶ added in v0.0.30
BroadcastFromPrefix calculates broadcast address from IPv4 prefix.Addr
func DisplayInterfaces ¶
func GetDefaultGatewayIPv4 ¶
func GetDefaultGatewayIPv4FromRoute ¶ added in v0.0.15
func GetDefaultGatewayIPv6 ¶ added in v0.0.20
func GetDefaultGatewayIPv6FromRoute ¶ added in v0.0.20
func GetDefaultInterface ¶
func GetDefaultInterfaceFromRoute ¶ added in v0.0.15
func GetDefaultInterfaceFromRouteIPv6 ¶ added in v0.0.21
func GetGatewayIPv6FromInterface ¶ added in v0.0.20
func GetHostIPv6GlobalUnicastFromRoute ¶ added in v0.0.21
func GetHostName ¶ added in v0.0.25
GetHostName performs the reverse DNS lookup for given address
func GetIPv6GlobalUnicastPrefixFromInterface ¶ added in v0.0.21
func GetIPv6LinkLocalUnicastPrefixFromInterface ¶ added in v0.0.21
func GetIPv6Resolver ¶ added in v0.0.28
GetIPv6Resolver returns first suitable IPv6 address from resolv.conf or Google IPv6 DNS as fallback
func GetPromiscuous ¶ added in v0.0.22
GetPromiscuous returns promiscuous mode bit value for given interface or -1 on error
func GetSystemNameservers ¶ added in v0.0.21
func InterfaceByName ¶
InterfaceByName returns the interface specified by name.
func Is6 ¶ added in v0.0.21
Is6 reports whether ip is an IPv6 address, excluding IPv4-mapped IPv6 addresses.
func IsLocalAddress ¶ added in v0.0.10
func ListenPacket ¶ added in v0.0.13
func ListenPacket(conf *ListenConfig) (*packet.Conn, error)
func ParseAddrPort ¶ added in v0.0.20
ParseAddrPort parses provided address value and tries to convert it to netip.AddrPort.
If address contains no IP (e.g. "80" or ":443"), it uses defaultHost to form address.
func PrettifyBytes ¶ added in v0.0.22
func SetPromiscuous ¶ added in v0.0.22
SetPromiscuous enables or disables promiscuous mode for given interface
Types ¶
type ListenConfig ¶ added in v0.0.13
type ListenConfig struct {
Device *net.Interface // network interface which to bind to, if not specified default interface is used
Protocol int // network protocol, defaults to ETH_P_ALL
Promiscuous *bool // enable or disable promiscuous mode
FilterExpr string // packet filter expression like in tcpdump
}