portmap icon indicating copy to clipboard operation
portmap copied to clipboard

:traffic_light: Port mapping library for Go supporting NAT-PMP and UPnP

NAT Port Mapping Library for Go

godocs.io Build status No modules 100% modules-free.

Example:

import "github.com/hlandau/portmap"
import "fmt"

func Example() {
  m, err := portmap.New(portmap.Config{
    Protocol:     portmap.TCP,
    Name:         "http",
    InternalPort:  80,
    ExternalPort:  80,
  })
  if err != nil {
    // ...
  }

  for {
    // mapping may change over time
    <-m.NotifyChan()
    fmt.Printf("Current mapped address is: %s\n", m.ExternalAddr())
  }

  // mapping will be renewed automatically
  // call m.Delete() when mapping should be torn down
}