Add a command to display all SSDP discoveries on local network.
This commit is contained in:
38
cmd/discoverall/discoverall.go
Normal file
38
cmd/discoverall/discoverall.go
Normal file
@ -0,0 +1,38 @@
|
||||
// Example program to display all devices discovered on the local network.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/huin/goupnp"
|
||||
"github.com/huin/goupnp/ssdp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func run() error {
|
||||
devices, err := goupnp.DiscoverDevices(ssdp.SSDPAll)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, device := range devices {
|
||||
fmt.Printf("Location: %v\n", device.Location)
|
||||
fmt.Printf("USN: %v\n", device.USN)
|
||||
if device.Err != nil {
|
||||
fmt.Printf(" Error: %v\n", device.Err)
|
||||
} else {
|
||||
fmt.Printf(" Root v%d.%d @ %s\n",
|
||||
device.Root.SpecVersion.Major, device.Root.SpecVersion.Minor,
|
||||
device.Root.URLBaseStr)
|
||||
fmt.Printf(" Type: %s\n", device.Root.Device.DeviceType)
|
||||
fmt.Printf(" Friendly name: %s\n", device.Root.Device.FriendlyName)
|
||||
fmt.Printf(" Num devices: %d\n", len(device.Root.Device.Devices))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user