ing
This commit is contained in:
49
discovery/protocol/upnp/upnp.go
Normal file
49
discovery/protocol/upnp/upnp.go
Normal file
@@ -0,0 +1,49 @@
|
||||
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) {
|
||||
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
|
||||
}
|
||||
|
||||
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(),
|
||||
})
|
||||
}
|
||||
}
|
||||
48
discovery/protocol/upnp/upnp_test.go
Normal file
48
discovery/protocol/upnp/upnp_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package upnp
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
omd "git.loafle.net/overflow/model/discovery"
|
||||
omm "git.loafle.net/overflow/model/meta"
|
||||
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
||||
)
|
||||
|
||||
func TestScan(t *testing.T) {
|
||||
s := session.MockDiscoverySession()
|
||||
s.InitWithDiscoverHost(
|
||||
nil,
|
||||
&omd.Zone{
|
||||
Network: "192.168.1.0/24",
|
||||
Iface: "enp3s0",
|
||||
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
||||
Address: "192.168.1.101",
|
||||
Mac: "44:8a:5b:f1:f1:f3",
|
||||
},
|
||||
&omd.DiscoverHost{
|
||||
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
||||
FirstScanRange: "192.168.1.1",
|
||||
LastScanRange: "192.168.1.254",
|
||||
},
|
||||
)
|
||||
|
||||
type args struct {
|
||||
discoverySession session.DiscoverySession
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
}{
|
||||
{
|
||||
name: "1",
|
||||
args: args{
|
||||
discoverySession: s,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
Scan(tt.args.discoverySession)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user