Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

lukechampine.com/upnp

Package Overview
Dependencies
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lukechampine.com/upnp

Go Modules
Version
v0.3.0
Version published
Created
Source

upnp

GoDoc Go Report Card

go get github.com/lukechampine/upnp

Yep, it's another package for forwarding ports and discovering your external IP address. This one has no dependencies and is ~1 MB smaller than huin/goupnp. It also offers a more flexible device scanning API: devices are returned via channel as soon as they respond (typically a few milliseconds) rather than all devices being returned after a timeout of 2 seconds (as in huin/goupnp).

Usage

// scan for router
d, _ := upnp.Discover(context.Background())

// connect to a previously-scanned router
routerURL := d.Location()
d, _ = upnp.Connect(context.Background(), routerURL)

// forward/clear a port
println(d.IsForwarded(15000, "TCP")) // false
d.Forward(15000, "TCP", "example description")
println(d.IsForwarded(15000, "TCP")) // true
d.Clear(15000, "TCP")
println(d.IsForwarded(15000, "TCP")) // false

// get external IP
ip, _ := d.ExternalIP()
println(ip)

FAQs

Package last updated on 15 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts