Skip to content
/ upnp Public
forked from scottjg/upnp

A simple implementation of the UPnP protocol. Add port mappings for devices behind NAT.

License

Notifications You must be signed in to change notification settings

kamilakis/upnp

 
 

Repository files navigation

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.

Examples:

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 gateway
	mapping.Reclaim()
} else {
	fmt.Println("failed:", err.Error())
}

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 gateway.

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

About

A simple implementation of the UPnP protocol. Add port mappings for devices behind NAT.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%