ing
This commit is contained in:
parent
a84f4eab12
commit
57cb5cf1a9
|
@ -7,12 +7,12 @@ import (
|
|||
omm "git.loafle.net/overflow/model/meta"
|
||||
)
|
||||
|
||||
const (
|
||||
ZONE_NETWORK = "192.168.1"
|
||||
ZONE_IFACE = "enp3s0"
|
||||
ZONE_ADDRESS = "101"
|
||||
ZONE_MAC = "44:8a:5b:f1:f1:f3"
|
||||
)
|
||||
// const (
|
||||
// ZONE_NETWORK = "192.168.1"
|
||||
// ZONE_IFACE = "enp3s0"
|
||||
// ZONE_ADDRESS = "101"
|
||||
// ZONE_MAC = "44:8a:5b:f1:f1:f3"
|
||||
// )
|
||||
|
||||
// const (
|
||||
// ZONE_NETWORK = "192.168.1"
|
||||
|
@ -21,6 +21,13 @@ const (
|
|||
// ZONE_MAC = "30:9C:23:15:A3:09"
|
||||
// )
|
||||
|
||||
const (
|
||||
ZONE_NETWORK = "192.168.35"
|
||||
ZONE_IFACE = "wlp5s0"
|
||||
ZONE_ADDRESS = "234"
|
||||
ZONE_MAC = "d0:7e:35:da:26:68"
|
||||
)
|
||||
|
||||
func Zone() *omd.Zone {
|
||||
return omd.NewZone(
|
||||
ZONE_IFACE,
|
||||
|
|
|
@ -131,7 +131,7 @@ LOOP:
|
|||
|
||||
canceled, ok := d.requestIds[req.RequestID()]
|
||||
delete(d.requestIds, req.RequestID())
|
||||
if !ok || canceled {
|
||||
if !ok || !canceled {
|
||||
req.(*ofDiscoveryRequest).release()
|
||||
continue LOOP
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ func (d *ofDiscoverer) hierarchyDiscover(s session.DiscoverySession) {
|
|||
|
||||
// post complexDiscover
|
||||
if nil != s.DiscoverPort() {
|
||||
discoveredHosts := s.DiscoveredAllHosts(true)
|
||||
discoveredHosts := s.DiscoveredAllHosts(false)
|
||||
for _, h := range discoveredHosts {
|
||||
wg.Add(1)
|
||||
go func(h *omd.Host) {
|
||||
|
|
|
@ -16,6 +16,9 @@ import (
|
|||
"github.com/google/gopacket/layers"
|
||||
)
|
||||
|
||||
var totalCount = 0
|
||||
var count = 0
|
||||
|
||||
func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) error {
|
||||
ps := discoverySession.PCapScanner()
|
||||
if nil == ps {
|
||||
|
@ -25,7 +28,13 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
|
|||
tcpChan := ps.OpenTCP(targetHost.Address)
|
||||
defer func() {
|
||||
ps.CloseTCP(targetHost.Address, tcpChan)
|
||||
count = count - 1
|
||||
log.Print("TCP -Count: ", count)
|
||||
}()
|
||||
count = count + 1
|
||||
log.Print("TCP +Count: ", count)
|
||||
totalCount = totalCount + 1
|
||||
log.Print("TCP Total Count: ", totalCount)
|
||||
|
||||
timerStopped := make(chan struct{})
|
||||
stopChan := make(chan struct{})
|
||||
|
|
|
@ -2,9 +2,13 @@ package upnp
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
omd "git.loafle.net/overflow/model/discovery"
|
||||
omm "git.loafle.net/overflow/model/meta"
|
||||
omu "git.loafle.net/overflow/model/util"
|
||||
oun "git.loafle.net/overflow/util-go/net"
|
||||
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
||||
"github.com/huin/goupnp"
|
||||
)
|
||||
|
@ -20,6 +24,7 @@ func Scan(discoverySession session.DiscoverySession) error {
|
|||
fmt.Println("DiscoverDevices: ", err)
|
||||
return nil
|
||||
}
|
||||
metaIPTypeEnum := omm.ToMetaIPTypeEnum(discoverySession.Zone().MetaIPType)
|
||||
|
||||
LOOP:
|
||||
for _, dev := range devs {
|
||||
|
@ -28,19 +33,29 @@ LOOP:
|
|||
continue LOOP
|
||||
}
|
||||
|
||||
h := omd.NewHost(
|
||||
discoverySession.Zone(),
|
||||
discoverySession.Zone().MetaIPType,
|
||||
rd.PresentationURL.URL.Host,
|
||||
)
|
||||
h.Name = rd.FriendlyName
|
||||
h.DiscoveredDate = omu.NowPtr()
|
||||
pURL := rd.PresentationURL.URL
|
||||
|
||||
discoverySession.AddHost(
|
||||
"UPnP",
|
||||
h,
|
||||
map[string]string{
|
||||
ip := oun.ParseIP(pURL.Hostname())
|
||||
if nil == ip {
|
||||
continue LOOP
|
||||
}
|
||||
|
||||
switch metaIPTypeEnum {
|
||||
case omm.MetaIPTypeEnumV4:
|
||||
if 4 != ip.Version() {
|
||||
continue LOOP
|
||||
}
|
||||
case omm.MetaIPTypeEnumV6:
|
||||
if 6 != ip.Version() {
|
||||
continue LOOP
|
||||
}
|
||||
default:
|
||||
continue LOOP
|
||||
}
|
||||
|
||||
meta := map[string]string{
|
||||
"DeviceType": rd.DeviceType,
|
||||
"FriendlyName": rd.FriendlyName,
|
||||
"Manufacturer": rd.Manufacturer,
|
||||
"ManufacturerURL": rd.ManufacturerURL.Str,
|
||||
"ModelName": rd.ModelName,
|
||||
|
@ -49,7 +64,68 @@ LOOP:
|
|||
"SerialNumber": rd.SerialNumber,
|
||||
"UDN": rd.UDN,
|
||||
"UPC": rd.UPC,
|
||||
},
|
||||
}
|
||||
|
||||
h := omd.NewHost(
|
||||
discoverySession.Zone(),
|
||||
discoverySession.Zone().MetaIPType,
|
||||
ip.String(),
|
||||
)
|
||||
h.Name = rd.ModelName
|
||||
h.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
discoverySession.AddHost(
|
||||
"UPnP",
|
||||
h,
|
||||
meta,
|
||||
)
|
||||
|
||||
portNumber, err := strconv.Atoi(pURL.Port())
|
||||
if nil != err {
|
||||
continue LOOP
|
||||
}
|
||||
|
||||
p := omd.NewPort(
|
||||
h,
|
||||
omm.ToMetaPortType(omm.MetaPortTypeEnumTCP),
|
||||
portNumber,
|
||||
)
|
||||
p.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
p = discoverySession.AddPort(
|
||||
"UPnP",
|
||||
p,
|
||||
meta,
|
||||
)
|
||||
|
||||
metaCryptoType := omm.ToMetaCryptoType(omm.MetaCryptoTypeEnumNONE)
|
||||
serviceType := omm.MetaServiceTypeEnumUNKNOWN.String()
|
||||
serviceKey := "UNKNOWN"
|
||||
|
||||
switch strings.ToLower(pURL.Scheme) {
|
||||
case "http":
|
||||
serviceKey = "HTTP"
|
||||
serviceType = omm.MetaServiceTypeEnumWeb.String()
|
||||
case "https":
|
||||
serviceKey = "HTTPS"
|
||||
metaCryptoType = omm.ToMetaCryptoType(omm.MetaCryptoTypeEnumTLS)
|
||||
serviceType = omm.MetaServiceTypeEnumWeb.String()
|
||||
default:
|
||||
}
|
||||
|
||||
s := omd.NewService(
|
||||
p,
|
||||
metaCryptoType,
|
||||
serviceKey,
|
||||
)
|
||||
s.Name = pURL.Scheme
|
||||
s.ServiceType = serviceType
|
||||
s.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
discoverySession.AddService(
|
||||
"UPnP",
|
||||
s,
|
||||
meta,
|
||||
)
|
||||
|
||||
select {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"log"
|
||||
"reflect"
|
||||
|
||||
oa "git.loafle.net/overflow/annotation-go"
|
||||
|
@ -31,5 +32,9 @@ func (s *MachineService) DestroyService() {
|
|||
}
|
||||
|
||||
func (s *MachineService) Interfaces() ([]*omn.Interface, error) {
|
||||
return nic.DiscoverInterfaces()
|
||||
ifaces, err := nic.DiscoverInterfaces()
|
||||
if nil != err {
|
||||
log.Print(err)
|
||||
}
|
||||
return ifaces, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user