probe/discovery/protocol/upnp/upnp.go
crusader 97184ea723 ing
2018-09-12 13:55:51 +09:00

64 lines
1.3 KiB
Go

package upnp
import (
"fmt"
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) error {
devs, err := goupnp.DiscoverDevices(TargetRootDevice)
if nil != err {
fmt.Println("DiscoverDevices: ", err)
return nil
}
LOOP:
for _, dev := range devs {
rd := dev.Root.Device
if !rd.PresentationURL.Ok {
continue LOOP
}
h := omd.NewHost(
discoverySession.Zone(),
discoverySession.Zone().MetaIPType,
rd.PresentationURL.URL.Host,
)
h.Name = rd.FriendlyName
h.DiscoveredDate = omu.NowPtr()
discoverySession.AddHost(
"UPnP",
h,
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,
},
)
select {
case <-discoverySession.StopChan():
return nil
default:
}
}
return nil
}