Last active
October 21, 2015 16:30
-
-
Save gr4y/b0b7fb18415ada341217 to your computer and use it in GitHub Desktop.
Go-Utility to discover UPNP Services over SSDP. Uses: http://github.com/huin/goupnp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/huin/goupnp" | |
) | |
func main() { | |
devices, err := goupnp.DiscoverDevices("upnp:rootdevice") | |
if err != nil { | |
fmt.Println(err) | |
} | |
if len(devices) > 0 { | |
for _, d := range devices { | |
fmt.Printf("Discovered device %s\n", d.Root.Device.String()) | |
ListServices(d.Root.Device.Services) | |
ListDevices(d.Root.Device.Devices) | |
} | |
} | |
} | |
func ListDevices(devices []goupnp.Device) { | |
if len(devices) > 0 { | |
for _, sd := range devices { | |
fmt.Printf("Discovered Device %s\n", sd.String()) | |
ListDevices(sd.Devices) | |
ListServices(sd.Services) | |
} | |
} | |
} | |
func ListServices(services []goupnp.Service) { | |
if len(services) > 0 { | |
for _, s := range services { | |
scpd, err := s.RequestSCDP() | |
fmt.Printf(" Discovered service %s\n", s.ServiceId) | |
if err != nil { | |
fmt.Printf(" Error requesting service SCPD: %v\n", err) | |
} else { | |
fmt.Println(" Available actions:") | |
for _, action := range scpd.Actions { | |
fmt.Printf(" * %s\n", action.Name) | |
for _, arg := range action.Arguments { | |
var varDesc string | |
if stateVar := scpd.GetStateVariable(arg.RelatedStateVariable); stateVar != nil { | |
varDesc = fmt.Sprintf(" (%s)", stateVar.DataType.Name) | |
} | |
fmt.Printf(" * [%s] %s%s\n", arg.Direction, arg.Name, varDesc) | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment