Documentation ¶
Overview ¶
Package nat provides access to common network port mapping protocols.
Index ¶
Constants ¶
const (
DefaultMapTimeout = 10 * time.Minute
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ExtIP ¶
ExtIP assumes that the local machine is reachable on the given external IP address, and that any required ports were mapped manually. Mapping operations will not return an error but won't actually do anything.
func (ExtIP) AddMapping ¶ added in v1.8.18
type Interface ¶
type Interface interface { // These methods manage a mapping between a port on the local // machine to a port that can be connected to from the internet. // // protocol is "UDP" or "TCP". Some implementations allow setting // a display name for the mapping. The mapping may be removed by // the gateway when its lifetime ends. AddMapping(protocol string, extport, intport int, name string, lifetime time.Duration) (uint16, error) DeleteMapping(protocol string, extport, intport int) error // ExternalIP should return the external (Internet-facing) // address of the gateway device. ExternalIP() (net.IP, error) // String should return name of the method. This is used for logging. String() string }
Interface An implementation of nat.Interface can map local ports to ports accessible from the Internet.
func Any ¶
func Any() Interface
Any returns a port mapper that tries to discover any supported mechanism on the local network.
func PMP ¶
PMP returns a port mapper that uses NAT-PMP. The provided gateway address should be the IP of your router. If the given gateway address is nil, PMP will attempt to auto-discover the router.
func Parse ¶
Parse parses a NAT interface description. The following formats are currently accepted. Note that mechanism names are not case-sensitive.
"" or "none" return nil "extip:77.12.33.4" will assume the local machine is reachable on the given IP "any" uses the first auto-detected mechanism "upnp" uses the Universal Plug and Play protocol "pmp" uses NAT-PMP with an auto-detected gateway address "pmp:192.168.0.1" uses NAT-PMP with the given gateway address