network

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: MPL-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package network provides network-related utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActiveAddresses

func ActiveAddresses() map[string]net.Interface

ActiveAddresses determines the best address for each active network interface. IPv4 addresses will be selected over IPv6 addresses on the same interface. Numeric addresses are resolved into names where possible.

func Address

func Address(iface net.Interface) string

Address returns the best address for the network interface. IPv4 addresses will be selected over IPv6 addresses on the same interface. Numeric addresses are resolved into names where possible. An empty string will be returned if the network interface cannot be resolved into an IPv4 or IPv6 address.

func AddressesForHost

func AddressesForHost(host string) []string

AddressesForHost returns the addresses/names for the given host. If an IP number is passed in, then it will be returned. If a host name is passed in, the host name plus the IP address(es) it resolves to will be returned. If the empty string is passed in, then the host names and IP addresses for all active interfaces will be returned.

func ExternalIP added in v1.2.2

func ExternalIP(timeout time.Duration) string

ExternalIP returns your IP address as seen by external sites. It does this by iterating through a list of websites that will return your IP address as they see it. The first response with a valid IP address will be returned. timeout sets the maximum amount of time for each attempt.

func PrimaryAddress

func PrimaryAddress() (hostname, ipAddress, macAddress string)

PrimaryAddress returns the primary hostname and its associated IP address and MAC address.

func PrimaryIPAddress

func PrimaryIPAddress() string

PrimaryIPAddress returns the primary IP address.

Types

type TCPKeepAliveListener

type TCPKeepAliveListener struct {
	*net.TCPListener
}

TCPKeepAliveListener sets TCP keep-alive timeouts on accepted connections so that dead TCP connections (e.g. closing laptop mid-download) eventually go away. This code was mostly copied from the http package, with changes to make it publicly accessible and to check some errors that were ignored.

func (TCPKeepAliveListener) Accept

func (listener TCPKeepAliveListener) Accept() (net.Conn, error)

Accept implements the Accept method in the Listener interface; it waits for the next call and returns a generic Conn.

Directories

Path Synopsis
Package natpmp provides an implementation of NAT-PMP.
Package natpmp provides an implementation of NAT-PMP.
Package xhttp provides HTTP-related utilities.
Package xhttp provides HTTP-related utilities.
web
Package web provides a web server with some standardized logging and handler wrapping.
Package web provides a web server with some standardized logging and handler wrapping.

Jump to

Keyboard shortcuts

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