A Go language client for the NAT-PMP internet protocol for port mapping and discovering the external IP address of a firewall.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jakob Borg 26d8705415 Remove auto discovering constructor
We don't use this method, and not having it lets us remove the
dependency on jackpal/gateway here, which is nice as we may want to keep
a fork with our own gateway code...
2016-05-22 14:56:46 +09:00
LICENSE Add license file 2013-01-01 13:07:38 -08:00
natpmp.go Remove auto discovering constructor 2016-05-22 14:56:46 +09:00
README.md Fix godoc link. 2014-08-21 21:10:29 -07:00

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.