natpmp

package
v0.2.3-buildfails Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2015 License: Apache-2.0, MIT Imports: 4 Imported by: 0

README

go-nat-pmp

A Go language client for the NAT-PMP internet protocol for port mapping and discovering the external IP address of a firewall.

NAT-PMP is supported by Apple brand routers and open source routers like Tomato and DD-WRT.

See http://tools.ietf.org/html/draft-cheshire-nat-pmp-03

Get the package

go get -u github.com/jackpal/go-nat-pmp

Usage

import natpmp "github.com/jackpal/go-nat-pmp"

client := natpmp.NewClient(gatewayIP)
response, err := client.GetExternalAddress()
if err != nil {
    return
}
print("External IP address:", response.ExternalIPAddress)

Notes

There doesn't seem to be an easy way to programmatically determine the address of the default gateway. (Linux and OSX have a "routes" kernel API that can be examined to get this information, but there is no Go package for getting this information.)

Clients

This library is used in the Taipei Torrent BitTorrent client http://github.com/jackpal/Taipei-Torrent

Complete documentation

http://godoc.org/github.com/jackpal/go-nat-pmp

License

This project is licensed under the Apache License 2.0.

Documentation

Index

Constants

View Source
const RECOMMENDED_MAPPING_LIFETIME_SECONDS = 3600

The recommended mapping lifetime for AddPortMapping

Variables

This section is empty.

Functions

This section is empty.

Types

type AddPortMappingResult

type AddPortMappingResult struct {
	SecondsSinceStartOfEpoc      uint32
	InternalPort                 uint16
	MappedExternalPort           uint16
	PortMappingLifetimeInSeconds uint32
}

Results of the NAT-PMP AddPortMapping operation

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a NAT-PMP protocol client.

func NewClient

func NewClient(gateway net.IP) (nat *Client)

Create a NAT-PMP client for the NAT-PMP server at the gateway.

func (*Client) AddPortMapping

func (n *Client) AddPortMapping(protocol string, internalPort, requestedExternalPort int, lifetime int) (result *AddPortMappingResult, err error)

Add (or delete) a port mapping. To delete a mapping, set the requestedExternalPort and lifetime to 0

func (*Client) GetExternalAddress

func (n *Client) GetExternalAddress() (result *GetExternalAddressResult, err error)

Get the external address of the router.

type GetExternalAddressResult

type GetExternalAddressResult struct {
	SecondsSinceStartOfEpoc uint32
	ExternalIPAddress       [4]byte
}

Results of the NAT-PMP GetExternalAddress operation

Jump to

Keyboard shortcuts

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