upnp

package module
v0.0.0-...-54610da Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: MIT Imports: 8 Imported by: 1

README

upnp

Golang UPNP implementation to open gateway ports and get WAN address

Available functons include:

  • GetPortMappings
  • AddMappingPort
  • DelMappingPort
  • ExternalIPAddress

Documentation

Index

Constants

View Source
const (
	// BroadcastRetryCount retry count
	BroadcastRetryCount = 3
	// BroadcastWaitTimeSeconds wait time
	BroadcastWaitTimeSeconds = 3
	// ServiceType service type
	ServiceType = "urn:schemas-upnp-org:service:WANIPConnection:1"
)

Variables

This section is empty.

Functions

func GetLocalAddress

func GetLocalAddress() net.IP

GetLocalAddress get the address of the local machine

Types

type Body

type Body struct {
	XMLName                            xml.Name                           `xml:"Body"`
	GetGenericPortMappingEntryResponse GetGenericPortMappingEntryResponse `xml:"GetGenericPortMappingEntryResponse"`
}

Body is the soap body

type Envelope

type Envelope struct {
	XMLName xml.Name `xml:"Envelope"`
	Body    Body     `xml:"Body"`
}

Envelope is a soap envelope

type Gateway

type Gateway struct {
	GatewayName   string
	Host          string
	DeviceDescURL string
	Cache         string
	ST            string
	ControlURL    string
	OutsideIP     net.IP
}

Gateway the router

type GetGenericPortMappingEntryResponse

type GetGenericPortMappingEntryResponse struct {
	XMLName                   xml.Name `xml:"GetGenericPortMappingEntryResponse"`
	NewRemoteHost             string   `xml:"NewRemoteHost"`
	NewExternalPort           int      `xml:"NewExternalPort"`
	NewProtocol               string   `xml:"NewProtocol"`
	NewInternalPort           int      `xml:"NewInternalPort"`
	NewInternalClient         string   `xml:"NewInternalClient"`
	NewEnabled                int      `xml:"NewEnabled"`
	NewPortMappingDescription string   `xml:"NewPortMappingDescription"`
	NewLeaseDuration          int      `xml:"NewLeaseDuration"`
}

GetGenericPortMappingEntryResponse is a port mapping

type Service

type Service struct {
	ServiceType string `xml:"serviceType"`
	//ServiceId   string `xml:"serviceId"`
	//SCPDURL     string `xml:"SCPDURL"`
	ControlURL string `xml:"controlURL"`
}

Service device Description xml elements

type UPNP

type UPNP struct {
	Gateway *Gateway
}

UPNP the upnp service

func NewUPNP

func NewUPNP() (*UPNP, error)

NewUPNP returns a new UPNP object with a populated Gateway object.

func (*UPNP) AddPortMapping

func (u *UPNP) AddPortMapping(localPort, remotePort int, protocol string) error

AddPortMapping to the WAN/Internet

func (*UPNP) DelPortMapping

func (u *UPNP) DelPortMapping(remotePort int, protocol string) error

DelPortMapping delete a port mapping

func (*UPNP) DeviceDesc

func (u *UPNP) DeviceDesc() error

DeviceDesc get the device description

func (*UPNP) ExternalIPAddress

func (u *UPNP) ExternalIPAddress() (net.IP, error)

ExternalIPAddress get the ip address of the router

func (*UPNP) GetPortMappings

func (u *UPNP) GetPortMappings() ([]Envelope, error)

GetPortMappings gets the port mappings

Jump to

Keyboard shortcuts

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