A simple implements UPnP protocol for Go(Golang) library. Add port mapping for NAT devices. Look for a gateway device, check if it supports UPnP, and if so, add port mappings.
Go to file
2020-12-22 16:24:13 -05:00
example Fixed import 2020-09-14 09:51:52 -04:00
AddPortMapping.go add duration/description fields in the port map api 2016-12-21 00:14:24 -08:00
common.go upnp is mostly for ipv4. this code is broken in ipv6 anyway 2016-12-25 18:59:56 -08:00
DelPortMapping.go Fix spelling of Gateway 2014-11-08 20:30:26 -06:00
DeviceDesc.go Fix spelling of Gateway 2014-11-08 20:30:26 -06:00
DeviceStatusInfo.go Fix spelling of Gateway 2014-11-08 20:30:26 -06:00
ExternalIPAddress.go Fix spelling of Gateway 2014-11-08 20:30:26 -06:00
GetGenericPortMappingEntry.go GetGenericPortMappingEntry 2020-12-22 16:21:02 -05:00
GetListOfPortMappings.go Protocol as param 2020-12-22 16:24:13 -05:00
go.mod GetGenericPortMappingEntry 2020-12-22 16:21:02 -05:00
message.go first commit 2014-06-26 19:57:22 +08:00
README.md translate some of the library to english 2016-12-20 20:39:11 -08:00
SearchGatewayMsg.go setTTL not yet supported on windows 2020-11-11 11:05:54 -05:00
ttl_other.go Rename ttl_windows.go to ttl_other.go 2020-11-12 08:54:35 -05:00
ttl_unix.go Update ttl_unix.go 2020-11-12 07:43:37 -05:00
upnp.go Protocol as param 2020-12-22 16:24:13 -05:00

upnp protocol

====

A simple implementation of the UPnP protocol as a Golang library. Add port mappings for NAT devices.

Look for a gateway device, check if it supports UPnP, and if so, add port mappings.

====

example:

1. add a port mapping

mapping := new(upnp.Upnp)
if err := mapping.AddPortMapping(55789, 55789, "TCP"); err == nil {
	fmt.Println("success !")
	// remove port mapping in gatway
	mapping.Reclaim()
} else {
	fmt.Println("fail !")
}

2. search gateway device.

upnpMan := new(upnp.Upnp)
err := upnpMan.SearchGateway()
if err != nil {
	fmt.Println(err.Error())
} else {
	fmt.Println("local ip address: ", upnpMan.LocalHost)
	fmt.Println("gateway ip address: ", upnpMan.Gateway.Host)
}

3. get an internet ip address in gatway.

upnpMan := new(upnp.Upnp)
err := upnpMan.ExternalIPAddr()
if err != nil {
	fmt.Println(err.Error())
} else {
	fmt.Println("internet ip address: ", upnpMan.GatewayOutsideIP)
}