goupnp/cmd/discoverall/discoverall.go

39 lines
918 B
Go
Raw Normal View History

// Example program to display all devices discovered on the local network.
package main
import (
"fmt"
"log"
2022-11-01 19:02:13 +00:00
"git.cyrilix.bzh/cyrilix/goupnp"
"git.cyrilix.bzh/cyrilix/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
}