Documentation ¶
Overview ¶
Easy for dialog with a UPnP device in golang
Index ¶
- Constants
- func GetIPAdress(_interface *net.Interface) string
- func GetInterfaceByIP(ip string) (*net.Interface, error)
- func GetInterfaceByName(name string) (*net.Interface, error)
- type Action
- type Argument
- func (a *Argument) GetAllowedValues() []string
- func (a *Argument) GetDefault() string
- func (a *Argument) GetDirection() string
- func (a *Argument) GetMaximum() string
- func (a *Argument) GetMinimum() string
- func (a *Argument) GetName() string
- func (a *Argument) GetStep() string
- func (a *Argument) GetType() string
- type Device
- func (d *Device) GetAllService() []*Service
- func (d *Device) GetDevices() []*Device
- func (d *Device) GetIconLink() []*Icon
- func (d *Device) GetServices() []*Service
- func (d *Device) GetServicesByType(typeName string) []*Service
- func (d *Device) HasDevice() bool
- func (d *Device) HasIcon() bool
- func (d *Device) HasService() bool
- type Error
- type Icon
- type Response
- type Root
- type Service
- type UPNP
- type XMLAction
- type XMLActionHead
- type XMLBody
- type XMLRepAction
- type XMLRepActionHead
- type XMLRepBody
- type XMLRepVariable
- type XMLVariable
Examples ¶
Constants ¶
const ( ALL_DEVICE = "upnp:rootdevice" SERVICE_GATEWAY_STATE = "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1" SERVICE_GATEWAY_IPV4_V1 = "urn:schemas-upnp-org:service:WANIPConnection:1" SERVICE_GATEWAY_IPV4_V2 = "urn:schemas-upnp-org:service:WANIPConnection:2" SERVICE_GATEWAY_IPV6 = "urn:schemas-upnp-org:service:WANIPv6FirewallControl:1" )
Exemple of service research
Variables ¶
This section is empty.
Functions ¶
func GetInterfaceByIP ¶
GetInterfaceByIP get interface by ip 192.168.1.1 (search by contain not exactly)
Types ¶
type Action ¶
type Action struct {
// contains filtered or unexported fields
}
Action usued for generate and read action
func (*Action) AddVariable ¶
AddVariable add data for argument
func (*Action) GetInArguments ¶
GetInArguments for get arguments
func (*Action) GetLastRequest ¶
GetLastRequest return last requet xml for debug
func (*Action) GetLastResponse ¶
GetLastResponse return last response xml
type Argument ¶
type Argument struct {
// contains filtered or unexported fields
}
Argument arguement
func (*Argument) GetAllowedValues ¶
GetAllowedValues return value possible
func (*Argument) GetDefault ¶
GetDefault return default string or ""
func (*Argument) GetDirection ¶
GetDirection return in or out
func (*Argument) GetMaximum ¶
GetMaximum return maximum or ""
func (*Argument) GetMinimum ¶
GetMinimum return minimum or ""
type Device ¶
type Device struct { XMLName xml.Name `xml:"device"` FriendlyName string `xml:"friendlyName"` Manufacturer string `xml:"manufacturer"` ManufacturerURL string `xml:"manufacturerURL"` ModelDescription string `xml:"modelDescription"` ModelName string `xml:"modelName"` ModelNumber string `xml:"modelNumber"` ModelURL string `xml:"modelURL"` SerialNumber string `xml:"serialNumber"` UDN string `xml:"UDN"` PresentationURL string `xml:"presentationURL"` Icons []*Icon `xml:"iconList>icon"` Devices []*Device `xml:"deviceList>device"` Services []*Service `xml:"serviceList>service"` // contains filtered or unexported fields }
Device data
func (*Device) GetAllService ¶
GetAllService returnn all services child in child
func (*Device) GetServices ¶
GetServices return contain service
func (*Device) GetServicesByType ¶
GetServicesByType return service if is a service name
func (*Device) HasService ¶
HasService return true if contain a service
type Error ¶
type Error struct { XMLName xml.Name `xml:"UPnPError"` ErrorCode string `xml:"errorCode"` ErrorDescription string `xml:"errorDescription"` }
Error format upnp error
type Icon ¶
type Icon struct { XMLName xml.Name `xml:"icon"` Mimetype string `xml:"mimetype"` Width int `xml:"width"` Height int `xml:"height"` Depth int `xml:"depth"` URL string `xml:"url"` }
Icon icon info
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response contain a response upnp
func (*Response) GetValueArgument ¶
GetValueArgument get value of argument
type Service ¶
type Service struct { XMLName xml.Name `xml:"service"` ServiceType string `xml:"serviceType"` ServiceID string `xml:"serviceId"` ControlURL string `xml:"controlURL"` EventSubURL string `xml:"eventSubURL"` SCPDURL string `xml:"SCPDURL"` // contains filtered or unexported fields }
Service for manipulation service
func (*Service) GetActions ¶
GetActions return all actions for the service
type UPNP ¶
type UPNP struct {
// contains filtered or unexported fields
}
UPNP is a struct for dialog on UPNP
func NewUPNP ¶
NewUPNP for create new UPNP request for type device
Example ¶
ExampleNewUPNP example for get external ipv4 address from gateway
package main import ( "bufio" "fmt" "net" "os" "strconv" "strings" ) func getInput() string { reader := bufio.NewReader(os.Stdin) str, _ := reader.ReadString('\n') return strings.TrimSpace(str) } func selectInterface() (*net.Interface, error) { addrs, _ := net.Interfaces() for n, addr := range addrs { ip, err := addr.Addrs() if err != nil { continue } fmt.Println(n, " : ", addr.Name, " {", addr.HardwareAddr, "} ", ip) } fmt.Print("Please select interface number : ") interfaceNum, err := strconv.ParseUint(getInput(), 10, 64) if err != nil { return nil, err } return &addrs[interfaceNum], nil } // ExampleNewUPNP example for get external ipv4 address from gateway func main() { up := NewUPNP(SERVICE_GATEWAY_IPV4_V2) _interface, err := selectInterface() if err != nil { panic(err) } devices := up.GetAllCompatibleDevice(_interface, 1) if len(devices) == 0 { return } services := devices[0].GetServicesByType(SERVICE_GATEWAY_IPV4_V2) if len(services) == 0 { return } service := services[0] response, err := service.GetAction("GetExternalIPAddress").Send() if err != nil { panic(err) } fmt.Println(response.ToString()) fmt.Print("Press enter") getInput() }
Output: external ip
func NewUPNPAllService ¶
func NewUPNPAllService() *UPNP
NewUPNPAllService for create new UPNP request for all type device
func (*UPNP) GetAllCompatibleDevice ¶
GetAllCompatibleDevice return All devices
type XMLAction ¶
type XMLAction struct { XMLName xml.Name Xmlns string `xml:"xmlns:u,attr"` Variables []XMLVariable `xml:",any"` }
XMLAction action
type XMLActionHead ¶
type XMLActionHead struct { XMLName xml.Name `xml:"s:Envelope"` Xmlns string `xml:"xmlns:s,attr"` EncodingStyle string `xml:"s:encodingStyle,attr"` Body XMLBody `xml:"s:Body"` }
XMLActionHead Header
type XMLRepAction ¶
type XMLRepAction struct { XMLName xml.Name Xmlns string `xml:"xmlns:u,attr"` Variables []XMLRepVariable `xml:",any"` }
XMLRepAction Action
type XMLRepActionHead ¶
type XMLRepActionHead struct { XMLName xml.Name `xml:"Envelope"` Xmlns string `xml:"xmlns:s,attr"` EncodingStyle string `xml:"encodingStyle,attr"` Body XMLRepBody `xml:"Body"` }
XMLRepActionHead Header
type XMLRepVariable ¶
XMLRepVariable variable
type XMLVariable ¶
XMLVariable variable