2018-08-29 12:04:23 +00:00
|
|
|
package upnp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-08-29 16:42:33 +00:00
|
|
|
"log"
|
2018-08-29 12:04:23 +00:00
|
|
|
|
|
|
|
omd "git.loafle.net/overflow/model/discovery"
|
|
|
|
omu "git.loafle.net/overflow/model/util"
|
|
|
|
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
|
|
|
"github.com/huin/goupnp"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
TargetRootDevice = "upnp:rootdevice"
|
|
|
|
TargetSSDPAll = "ssdp:all"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Scan(discoverySession session.DiscoverySession) {
|
|
|
|
devs, err := goupnp.DiscoverDevices(TargetRootDevice)
|
|
|
|
if nil != err {
|
|
|
|
fmt.Println("DeletePortMapping: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
LOOP:
|
|
|
|
for _, dev := range devs {
|
|
|
|
rd := dev.Root.Device
|
|
|
|
if !rd.PresentationURL.Ok {
|
|
|
|
continue LOOP
|
|
|
|
}
|
|
|
|
|
2018-08-29 16:42:33 +00:00
|
|
|
log.Print(rd)
|
|
|
|
|
2018-08-29 12:04:23 +00:00
|
|
|
discoverySession.AddHost(&omd.Host{
|
|
|
|
MetaIPType: discoverySession.Zone().MetaIPType,
|
|
|
|
Name: rd.FriendlyName,
|
|
|
|
Address: rd.PresentationURL.URL.Host,
|
|
|
|
Meta: map[string]string{
|
|
|
|
"DeviceType": rd.DeviceType,
|
|
|
|
"Manufacturer": rd.Manufacturer,
|
|
|
|
"ManufacturerURL": rd.ManufacturerURL.Str,
|
|
|
|
"ModelName": rd.ModelName,
|
|
|
|
"ModelDescription": rd.ModelDescription,
|
|
|
|
"ModelNumber": rd.ModelNumber,
|
|
|
|
"SerialNumber": rd.SerialNumber,
|
|
|
|
"UDN": rd.UDN,
|
|
|
|
"UPC": rd.UPC,
|
|
|
|
},
|
|
|
|
Zone: discoverySession.Zone(),
|
|
|
|
DiscoveredDate: omu.NowPtr(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|