igd

package module
v0.0.0-...-4320956 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2020 License: MPL-2.0 Imports: 13 Imported by: 1

README

go-upnp-igd

GoDoc

Minimal Go UPnP InternetGatewayDevice library. Based on Syncthing's library.

Usage

package main

import (
	"log"
	"time"

	"github.com/emersion/go-upnp-igd"
)

func main() {
	devices := make(chan igd.Device)
	go func() {
		for d := range devices {
			log.Println(d)
		}
	}()

	err := igd.Discover(devices, 30*time.Second)
	if err != nil {
		log.Fatal(err)
	}
}

License

MPL 2.0

Documentation

Overview

Package igd implements UPnP InternetGatewayDevice discovery, querying, and port mapping.

Index

Constants

This section is empty.

Variables

View Source
var Logger interface {
	Printf(format string, v ...interface{})
	Println(v ...interface{})
} = nopLogger{}

Functions

func Discover

func Discover(ch chan<- Device, timeout time.Duration) error

Discover discovers UPnP InternetGatewayDevices. The order in which the devices appear in the results list is not deterministic.

Types

type Device

type Device interface {
	ID() string
	GetLocalIPAddress() net.IP
	AddPortMapping(protocol Protocol, internalPort, externalPort int, description string, duration time.Duration) (int, error)
	GetExternalIPAddress() (net.IP, error)
}

type IGD

type IGD struct {
	// contains filtered or unexported fields
}

An IGD is a UPnP InternetGatewayDevice.

func (*IGD) AddPortMapping

func (n *IGD) AddPortMapping(protocol Protocol, internalPort, externalPort int, description string, duration time.Duration) (int, error)

AddPortMapping adds a port mapping to all relevant services on the specified InternetGatewayDevice. Port mapping will fail and return an error if action is fails for _any_ of the relevant services. For this reason, it is generally better to configure port mapping for each individual service instead.

func (*IGD) DeletePortMapping

func (n *IGD) DeletePortMapping(protocol Protocol, externalPort int) error

DeletePortMapping deletes a port mapping from all relevant services on the specified InternetGatewayDevice. Port mapping will fail and return an error if action is fails for _any_ of the relevant services. For this reason, it is generally better to configure port mapping for each individual service instead.

func (*IGD) FriendlyIdentifier

func (n *IGD) FriendlyIdentifier() string

FriendlyIdentifier returns a friendly identifier (friendly name + IP address) for the IGD.

func (*IGD) FriendlyName

func (n *IGD) FriendlyName() string

func (*IGD) GetExternalIPAddress

func (n *IGD) GetExternalIPAddress() (ip net.IP, err error)

GetExternalIPAddress returns the external IP address of the IGD, or an error if no service providing this feature exists.

func (*IGD) GetLocalIPAddress

func (n *IGD) GetLocalIPAddress() net.IP

GetLocalIPAddress returns the IP address of the local network interface which is facing the IGD.

func (*IGD) ID

func (n *IGD) ID() string

func (*IGD) URL

func (n *IGD) URL() *url.URL

type IGDService

type IGDService struct {
	ID  string
	URL string
	URN string
}

An IGDService is a specific service provided by an IGD.

func (*IGDService) AddPortMapping

func (s *IGDService) AddPortMapping(localIPAddress net.IP, protocol Protocol, internalPort, externalPort int, description string, duration time.Duration) error

AddPortMapping adds a port mapping to the specified IGD service.

func (*IGDService) DeletePortMapping

func (s *IGDService) DeletePortMapping(protocol Protocol, externalPort int) error

DeletePortMapping deletes a port mapping from the specified IGD service.

func (*IGDService) GetExternalIPAddress

func (s *IGDService) GetExternalIPAddress() (net.IP, error)

GetExternalIPAddress queries the IGD service for its external IP address. Returns nil if the external IP address is invalid or undefined, along with any relevant errors

type Protocol

type Protocol string
const (
	TCP Protocol = "TCP"
	UDP          = "UDP"
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL