test modified
This commit is contained in:
parent
5956cae93f
commit
6f259e2d9d
74
__test/test.go
Normal file
74
__test/test.go
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
package __test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
omd "git.loafle.net/overflow/model/discovery"
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Zone() *omd.Zone {
|
||||||
|
return &omd.Zone{
|
||||||
|
Network: fmt.Sprintf("%s.0/24", ZONE_NETWORK),
|
||||||
|
Iface: ZONE_IFACE,
|
||||||
|
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
||||||
|
Address: fmt.Sprintf("%s.$s", ZONE_ADDRESS),
|
||||||
|
Mac: ZONE_MAC,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Host(hostName string, address string, mac string) *omd.Host {
|
||||||
|
return &omd.Host{
|
||||||
|
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
||||||
|
Name: hostName,
|
||||||
|
Address: fmt.Sprintf("%s.$s", address),
|
||||||
|
Mac: mac,
|
||||||
|
Zone: Zone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Port(host *omd.Host, port string) *omd.Port {
|
||||||
|
return &omd.Port{
|
||||||
|
MetaPortType: omm.ToMetaPortType(omm.MetaPortTypeEnumTCP),
|
||||||
|
PortNumber: json.Number(port),
|
||||||
|
Host: host,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DiscoveryConfig() *omd.DiscoveryConfig {
|
||||||
|
return &omd.DiscoveryConfig{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DiscoverHost(discoveryConfig *omd.DiscoveryConfig, firstScanRange int, lastScanRange int, discoverPort *omd.DiscoverPort) *omd.DiscoverHost {
|
||||||
|
return &omd.DiscoverHost{
|
||||||
|
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
||||||
|
FirstScanRange: fmt.Sprintf("%s.%d", ZONE_NETWORK, firstScanRange),
|
||||||
|
LastScanRange: fmt.Sprintf("%s.%d", ZONE_NETWORK, lastScanRange),
|
||||||
|
DiscoveryConfig: discoveryConfig,
|
||||||
|
DiscoverPort: discoverPort,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DiscoverPort(discoveryConfig *omd.DiscoveryConfig, firstScanRange int, lastScanRange int, includeTCP bool, includeUDP bool, discoverService *omd.DiscoverService) *omd.DiscoverPort {
|
||||||
|
return &omd.DiscoverPort{
|
||||||
|
FirstScanRange: firstScanRange,
|
||||||
|
LastScanRange: lastScanRange,
|
||||||
|
IncludeTCP: includeTCP,
|
||||||
|
IncludeUDP: includeUDP,
|
||||||
|
DiscoverService: discoverService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DiscoverService(discoveryConfig *omd.DiscoveryConfig) *omd.DiscoverService {
|
||||||
|
return &omd.DiscoverService{
|
||||||
|
DiscoveryConfig: discoveryConfig,
|
||||||
|
}
|
||||||
|
}
|
|
@ -263,6 +263,36 @@ func (d *ofDiscoverer) hierarchyDiscover(s session.DiscoverySession) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// post complexDiscover
|
||||||
|
if nil != s.DiscoverPort() {
|
||||||
|
discoveredHosts := s.DiscoveredAllHosts()
|
||||||
|
for _, h := range discoveredHosts {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(h *omd.Host) {
|
||||||
|
defer wg.Done()
|
||||||
|
port.Scan(s, h)
|
||||||
|
}(h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
if nil != s.DiscoverService() {
|
||||||
|
discoveredPorts := s.DiscoveredAllPorts()
|
||||||
|
for _, hostPorts := range discoveredPorts {
|
||||||
|
for _, ports := range hostPorts {
|
||||||
|
for _, p := range ports {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(p *omd.Port) {
|
||||||
|
defer wg.Done()
|
||||||
|
service.Scan(s, p)
|
||||||
|
}(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
// exec hierarchy Discovery
|
||||||
if nil != s.DiscoverHost() {
|
if nil != s.DiscoverHost() {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
omd "git.loafle.net/overflow/model/discovery"
|
omd "git.loafle.net/overflow/model/discovery"
|
||||||
omm "git.loafle.net/overflow/model/meta"
|
omm "git.loafle.net/overflow/model/meta"
|
||||||
omu "git.loafle.net/overflow/model/util"
|
omu "git.loafle.net/overflow/model/util"
|
||||||
|
oub "git.loafle.net/overflow/util-go/benchmark"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
||||||
"git.loafle.net/overflow_scanner/probe/internal/pcap"
|
"git.loafle.net/overflow_scanner/probe/internal/pcap"
|
||||||
"github.com/google/gopacket"
|
"github.com/google/gopacket"
|
||||||
|
@ -17,6 +18,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Scan(discoverySession session.DiscoverySession) error {
|
func Scan(discoverySession session.DiscoverySession) error {
|
||||||
|
oub.Elapsed("mDNS")
|
||||||
|
|
||||||
targetHosts := discoverySession.TargetHosts()
|
targetHosts := discoverySession.TargetHosts()
|
||||||
if nil == targetHosts || 0 == len(targetHosts) {
|
if nil == targetHosts || 0 == len(targetHosts) {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
omd "git.loafle.net/overflow/model/discovery"
|
omd "git.loafle.net/overflow/model/discovery"
|
||||||
omm "git.loafle.net/overflow/model/meta"
|
"git.loafle.net/overflow_scanner/probe/__test"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
||||||
"git.loafle.net/overflow_scanner/probe/internal/pcap"
|
"git.loafle.net/overflow_scanner/probe/internal/pcap"
|
||||||
|
@ -17,19 +17,8 @@ func TestScan(t *testing.T) {
|
||||||
s := session.NewMockDiscoverySession(
|
s := session.NewMockDiscoverySession(
|
||||||
"testRequester",
|
"testRequester",
|
||||||
types.DiscoveryRequestTypeHost,
|
types.DiscoveryRequestTypeHost,
|
||||||
&omd.Zone{
|
__test.Zone(),
|
||||||
Network: "192.168.1.0/24",
|
__test.DiscoverHost(__test.DiscoveryConfig(), 1, 254, nil),
|
||||||
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",
|
|
||||||
DiscoveryConfig: &omd.DiscoveryConfig{},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
omd "git.loafle.net/overflow/model/discovery"
|
omd "git.loafle.net/overflow/model/discovery"
|
||||||
omm "git.loafle.net/overflow/model/meta"
|
"git.loafle.net/overflow_scanner/probe/__test"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
||||||
"git.loafle.net/overflow_scanner/probe/internal/pcap"
|
"git.loafle.net/overflow_scanner/probe/internal/pcap"
|
||||||
|
@ -17,19 +17,8 @@ func Test_scanV4(t *testing.T) {
|
||||||
s := session.NewMockDiscoverySession(
|
s := session.NewMockDiscoverySession(
|
||||||
"testRequester",
|
"testRequester",
|
||||||
types.DiscoveryRequestTypeHost,
|
types.DiscoveryRequestTypeHost,
|
||||||
&omd.Zone{
|
__test.Zone(),
|
||||||
Network: "192.168.1.0/24",
|
__test.DiscoverHost(__test.DiscoveryConfig(), 1, 254, nil),
|
||||||
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",
|
|
||||||
DiscoveryConfig: &omd.DiscoveryConfig{},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
|
|
|
@ -13,11 +13,13 @@ import (
|
||||||
omd "git.loafle.net/overflow/model/discovery"
|
omd "git.loafle.net/overflow/model/discovery"
|
||||||
omm "git.loafle.net/overflow/model/meta"
|
omm "git.loafle.net/overflow/model/meta"
|
||||||
omu "git.loafle.net/overflow/model/util"
|
omu "git.loafle.net/overflow/model/util"
|
||||||
|
oub "git.loafle.net/overflow/util-go/benchmark"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
||||||
"github.com/grandcat/zeroconf"
|
"github.com/grandcat/zeroconf"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Scan(discoverySession session.DiscoverySession) error {
|
func Scan(discoverySession session.DiscoverySession) error {
|
||||||
|
oub.Elapsed("mDNS")
|
||||||
serviceEntries, err := browse("_services._dns-sd._udp", "local")
|
serviceEntries, err := browse("_services._dns-sd._udp", "local")
|
||||||
if nil != err {
|
if nil != err {
|
||||||
log.Print("Cannot find service ", err)
|
log.Print("Cannot find service ", err)
|
||||||
|
@ -179,14 +181,14 @@ func browse(service string, domain string) ([]*zeroconf.ServiceEntry, error) {
|
||||||
|
|
||||||
serviceEntries := make([]*zeroconf.ServiceEntry, 0)
|
serviceEntries := make([]*zeroconf.ServiceEntry, 0)
|
||||||
|
|
||||||
go func(_entryChan <-chan *zeroconf.ServiceEntry) {
|
go func(entryChan <-chan *zeroconf.ServiceEntry) {
|
||||||
var delay atomic.Value
|
var delay atomic.Value
|
||||||
delay.Store(false)
|
delay.Store(false)
|
||||||
ticker := time.NewTicker(time.Second * 1)
|
ticker := time.NewTicker(time.Second * 1)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case entry, ok := <-_entryChan:
|
case entry, ok := <-entryChan:
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -203,7 +205,7 @@ func browse(service string, domain string) ([]*zeroconf.ServiceEntry, error) {
|
||||||
}
|
}
|
||||||
}(entryChan)
|
}(entryChan)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(30))
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(3))
|
||||||
defer cancel()
|
defer cancel()
|
||||||
err = resolver.Browse(ctx, service, domain, entryChan)
|
err = resolver.Browse(ctx, service, domain, entryChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -4,8 +4,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
omd "git.loafle.net/overflow/model/discovery"
|
"git.loafle.net/overflow_scanner/probe/__test"
|
||||||
omm "git.loafle.net/overflow/model/meta"
|
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
||||||
"github.com/grandcat/zeroconf"
|
"github.com/grandcat/zeroconf"
|
||||||
|
@ -15,19 +14,8 @@ func TestScan(t *testing.T) {
|
||||||
s := session.NewMockDiscoverySession(
|
s := session.NewMockDiscoverySession(
|
||||||
"testRequester",
|
"testRequester",
|
||||||
types.DiscoveryRequestTypeHost,
|
types.DiscoveryRequestTypeHost,
|
||||||
&omd.Zone{
|
__test.Zone(),
|
||||||
Network: "192.168.1.0/24",
|
__test.DiscoverHost(__test.DiscoveryConfig(), 1, 254, nil),
|
||||||
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",
|
|
||||||
DiscoveryConfig: &omd.DiscoveryConfig{},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
|
|
|
@ -5,8 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
omcc "git.loafle.net/overflow/model/config/credential"
|
omcc "git.loafle.net/overflow/model/config/credential"
|
||||||
omd "git.loafle.net/overflow/model/discovery"
|
"git.loafle.net/overflow_scanner/probe/__test"
|
||||||
omm "git.loafle.net/overflow/model/meta"
|
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
||||||
)
|
)
|
||||||
|
@ -15,19 +14,8 @@ func TestScan(t *testing.T) {
|
||||||
s := session.NewMockDiscoverySession(
|
s := session.NewMockDiscoverySession(
|
||||||
"testRequester",
|
"testRequester",
|
||||||
types.DiscoveryRequestTypeHost,
|
types.DiscoveryRequestTypeHost,
|
||||||
&omd.Zone{
|
__test.Zone(),
|
||||||
Network: "192.168.1.0/24",
|
__test.DiscoverHost(__test.DiscoveryConfig(), 1, 254, nil),
|
||||||
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",
|
|
||||||
DiscoveryConfig: &omd.DiscoveryConfig{},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
omd "git.loafle.net/overflow/model/discovery"
|
omd "git.loafle.net/overflow/model/discovery"
|
||||||
omm "git.loafle.net/overflow/model/meta"
|
"git.loafle.net/overflow_scanner/probe/__test"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
||||||
)
|
)
|
||||||
|
@ -14,33 +14,27 @@ func TestScan(t *testing.T) {
|
||||||
s := session.NewMockDiscoverySession(
|
s := session.NewMockDiscoverySession(
|
||||||
"testRequester",
|
"testRequester",
|
||||||
types.DiscoveryRequestTypeHost,
|
types.DiscoveryRequestTypeHost,
|
||||||
&omd.Zone{
|
__test.Zone(),
|
||||||
Network: "192.168.1.0/24",
|
__test.DiscoverHost(
|
||||||
Iface: "enp3s0",
|
__test.DiscoveryConfig(),
|
||||||
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
1,
|
||||||
Address: "192.168.1.101",
|
254,
|
||||||
Mac: "44:8a:5b:f1:f1:f3",
|
__test.DiscoverPort(
|
||||||
},
|
nil,
|
||||||
&omd.DiscoverHost{
|
1,
|
||||||
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
65535,
|
||||||
FirstScanRange: "192.168.1.1",
|
true,
|
||||||
LastScanRange: "192.168.1.254",
|
false,
|
||||||
DiscoveryConfig: &omd.DiscoveryConfig{},
|
nil,
|
||||||
DiscoverPort: &omd.DiscoverPort{
|
),
|
||||||
FirstScanRange: 1,
|
),
|
||||||
LastScanRange: 65535,
|
|
||||||
IncludeTCP: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
targetHost := &omd.Host{
|
targetHost := __test.Host(
|
||||||
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
"atGame",
|
||||||
Name: "atGame",
|
"1",
|
||||||
Address: "192.168.1.1",
|
"00:11:32:7f:20:61",
|
||||||
Mac: "00:11:32:7f:20:61",
|
)
|
||||||
Zone: s.Zone(),
|
|
||||||
}
|
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
discoverySession session.DiscoverySession
|
discoverySession session.DiscoverySession
|
||||||
|
@ -85,7 +79,7 @@ func Test_scanPort(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
scanPort(tt.args.discoverySession, tt.args.ports, tt.args.targetHost, tt.args.port, tt.args.timeout)
|
tryConnect(tt.args.discoverySession, tt.args.ports, tt.args.targetHost, tt.args.port, tt.args.timeout)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
omd "git.loafle.net/overflow/model/discovery"
|
omd "git.loafle.net/overflow/model/discovery"
|
||||||
omm "git.loafle.net/overflow/model/meta"
|
"git.loafle.net/overflow_scanner/probe/__test"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
||||||
"git.loafle.net/overflow_scanner/probe/internal/pcap"
|
"git.loafle.net/overflow_scanner/probe/internal/pcap"
|
||||||
|
@ -16,33 +16,27 @@ func Test_scanV4(t *testing.T) {
|
||||||
s := session.NewMockDiscoverySession(
|
s := session.NewMockDiscoverySession(
|
||||||
"testRequester",
|
"testRequester",
|
||||||
types.DiscoveryRequestTypeHost,
|
types.DiscoveryRequestTypeHost,
|
||||||
&omd.Zone{
|
__test.Zone(),
|
||||||
Network: "192.168.1.0/24",
|
__test.DiscoverHost(
|
||||||
Iface: "enp3s0",
|
__test.DiscoveryConfig(),
|
||||||
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
1,
|
||||||
Address: "192.168.1.101",
|
254,
|
||||||
Mac: "44:8a:5b:f1:f1:f3",
|
__test.DiscoverPort(
|
||||||
},
|
nil,
|
||||||
&omd.DiscoverHost{
|
1,
|
||||||
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
65535,
|
||||||
FirstScanRange: "192.168.1.1",
|
true,
|
||||||
LastScanRange: "192.168.1.254",
|
false,
|
||||||
DiscoveryConfig: &omd.DiscoveryConfig{},
|
nil,
|
||||||
DiscoverPort: &omd.DiscoverPort{
|
),
|
||||||
FirstScanRange: 1,
|
),
|
||||||
LastScanRange: 1024,
|
|
||||||
IncludeTCP: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
targetHost := &omd.Host{
|
targetHost := __test.Host(
|
||||||
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
"atGame",
|
||||||
Name: "atGame",
|
"1",
|
||||||
Address: "192.168.1.1",
|
"00:11:32:7f:20:61",
|
||||||
Mac: "00:11:32:7f:20:61",
|
)
|
||||||
Zone: s.Zone(),
|
|
||||||
}
|
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
discoverySession session.DiscoverySession
|
discoverySession session.DiscoverySession
|
||||||
|
|
|
@ -3,8 +3,7 @@ package upnp
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
omd "git.loafle.net/overflow/model/discovery"
|
"git.loafle.net/overflow_scanner/probe/__test"
|
||||||
omm "git.loafle.net/overflow/model/meta"
|
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
||||||
)
|
)
|
||||||
|
@ -13,19 +12,8 @@ func TestScan(t *testing.T) {
|
||||||
s := session.NewMockDiscoverySession(
|
s := session.NewMockDiscoverySession(
|
||||||
"testRequester",
|
"testRequester",
|
||||||
types.DiscoveryRequestTypeHost,
|
types.DiscoveryRequestTypeHost,
|
||||||
&omd.Zone{
|
__test.Zone(),
|
||||||
Network: "192.168.1.0/24",
|
__test.DiscoverHost(__test.DiscoveryConfig(), 1, 254, nil),
|
||||||
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",
|
|
||||||
DiscoveryConfig: &omd.DiscoveryConfig{},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
|
|
|
@ -36,8 +36,11 @@ type DiscoverySession interface {
|
||||||
AddService(service *omd.Service) *omd.Service
|
AddService(service *omd.Service) *omd.Service
|
||||||
|
|
||||||
DiscoveredHost(address string) *omd.Host
|
DiscoveredHost(address string) *omd.Host
|
||||||
|
DiscoveredAllHosts() map[string]*omd.Host
|
||||||
DiscoveredPort(host *omd.Host, portNumber int) map[string]*omd.Port
|
DiscoveredPort(host *omd.Host, portNumber int) map[string]*omd.Port
|
||||||
|
DiscoveredAllPorts() map[*omd.Host]map[json.Number]map[string]*omd.Port
|
||||||
DiscoveredService(port *omd.Port, name string) map[string]*omd.Service
|
DiscoveredService(port *omd.Port, name string) map[string]*omd.Service
|
||||||
|
DiscoveredAllServices() map[*omd.Port]map[string]map[string]*omd.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
type ofDiscoverySession struct {
|
type ofDiscoverySession struct {
|
||||||
|
@ -257,6 +260,10 @@ func (ds *ofDiscoverySession) DiscoveredHost(address string) *omd.Host {
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ds *ofDiscoverySession) DiscoveredAllHosts() map[string]*omd.Host {
|
||||||
|
return ds.hosts
|
||||||
|
}
|
||||||
|
|
||||||
func (ds *ofDiscoverySession) DiscoveredPort(host *omd.Host, portNumber int) map[string]*omd.Port {
|
func (ds *ofDiscoverySession) DiscoveredPort(host *omd.Host, portNumber int) map[string]*omd.Port {
|
||||||
h, _ := ds.findHost(host, false)
|
h, _ := ds.findHost(host, false)
|
||||||
if nil == h {
|
if nil == h {
|
||||||
|
@ -276,6 +283,10 @@ func (ds *ofDiscoverySession) DiscoveredPort(host *omd.Host, portNumber int) map
|
||||||
return ports
|
return ports
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ds *ofDiscoverySession) DiscoveredAllPorts() map[*omd.Host]map[json.Number]map[string]*omd.Port {
|
||||||
|
return ds.ports
|
||||||
|
}
|
||||||
|
|
||||||
func (ds *ofDiscoverySession) DiscoveredService(port *omd.Port, name string) map[string]*omd.Service {
|
func (ds *ofDiscoverySession) DiscoveredService(port *omd.Port, name string) map[string]*omd.Service {
|
||||||
p, _ := ds.findPort(port, false)
|
p, _ := ds.findPort(port, false)
|
||||||
if nil == p {
|
if nil == p {
|
||||||
|
@ -295,6 +306,10 @@ func (ds *ofDiscoverySession) DiscoveredService(port *omd.Port, name string) map
|
||||||
return services
|
return services
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ds *ofDiscoverySession) DiscoveredAllServices() map[*omd.Port]map[string]map[string]*omd.Service {
|
||||||
|
return ds.services
|
||||||
|
}
|
||||||
|
|
||||||
func (ds *ofDiscoverySession) findHost(host *omd.Host, add bool) (h *omd.Host, modified bool) {
|
func (ds *ofDiscoverySession) findHost(host *omd.Host, add bool) (h *omd.Host, modified bool) {
|
||||||
modified = false
|
modified = false
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
omd "git.loafle.net/overflow/model/discovery"
|
omd "git.loafle.net/overflow/model/discovery"
|
||||||
omm "git.loafle.net/overflow/model/meta"
|
|
||||||
osm "git.loafle.net/overflow/service_matcher-go"
|
osm "git.loafle.net/overflow/service_matcher-go"
|
||||||
|
"git.loafle.net/overflow_scanner/probe/__test"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
||||||
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
||||||
)
|
)
|
||||||
|
@ -17,64 +16,29 @@ func Test_scanTCP(t *testing.T) {
|
||||||
s := session.NewMockDiscoverySession(
|
s := session.NewMockDiscoverySession(
|
||||||
"testRequester",
|
"testRequester",
|
||||||
types.DiscoveryRequestTypeHost,
|
types.DiscoveryRequestTypeHost,
|
||||||
&omd.Zone{
|
__test.Zone(),
|
||||||
Network: "192.168.1.0/24",
|
__test.DiscoverHost(
|
||||||
Iface: "enp3s0",
|
__test.DiscoveryConfig(),
|
||||||
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
1,
|
||||||
Address: "192.168.1.101",
|
254,
|
||||||
Mac: "44:8a:5b:f1:f1:f3",
|
__test.DiscoverPort(
|
||||||
},
|
nil,
|
||||||
&omd.DiscoverHost{
|
1,
|
||||||
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
65535,
|
||||||
FirstScanRange: "192.168.1.1",
|
true,
|
||||||
LastScanRange: "192.168.1.254",
|
false,
|
||||||
DiscoveryConfig: &omd.DiscoveryConfig{},
|
__test.DiscoverService(
|
||||||
DiscoverPort: &omd.DiscoverPort{
|
nil,
|
||||||
FirstScanRange: 1,
|
),
|
||||||
LastScanRange: 1024,
|
),
|
||||||
IncludeTCP: true,
|
),
|
||||||
DiscoverService: &omd.DiscoverService{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
targetHost := &omd.Host{
|
targetHost := __test.Host(
|
||||||
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
|
"atGame",
|
||||||
Name: "atGame",
|
"1",
|
||||||
Address: "192.168.1.1",
|
"00:11:32:7f:20:61",
|
||||||
Mac: "00:11:32:7f:20:61",
|
)
|
||||||
Zone: s.Zone(),
|
|
||||||
}
|
|
||||||
|
|
||||||
targetPort80 := &omd.Port{
|
|
||||||
MetaPortType: omm.ToMetaPortType(omm.MetaPortTypeEnumTCP),
|
|
||||||
PortNumber: json.Number("80"),
|
|
||||||
Host: targetHost,
|
|
||||||
}
|
|
||||||
|
|
||||||
targetPort139 := &omd.Port{
|
|
||||||
MetaPortType: omm.ToMetaPortType(omm.MetaPortTypeEnumTCP),
|
|
||||||
PortNumber: json.Number("139"),
|
|
||||||
Host: targetHost,
|
|
||||||
}
|
|
||||||
|
|
||||||
targetPort443 := &omd.Port{
|
|
||||||
MetaPortType: omm.ToMetaPortType(omm.MetaPortTypeEnumTCP),
|
|
||||||
PortNumber: json.Number("443"),
|
|
||||||
Host: targetHost,
|
|
||||||
}
|
|
||||||
|
|
||||||
targetPort445 := &omd.Port{
|
|
||||||
MetaPortType: omm.ToMetaPortType(omm.MetaPortTypeEnumTCP),
|
|
||||||
PortNumber: json.Number("445"),
|
|
||||||
Host: targetHost,
|
|
||||||
}
|
|
||||||
|
|
||||||
targetPort548 := &omd.Port{
|
|
||||||
MetaPortType: omm.ToMetaPortType(omm.MetaPortTypeEnumTCP),
|
|
||||||
PortNumber: json.Number("548"),
|
|
||||||
Host: targetHost,
|
|
||||||
}
|
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
discoverySession session.DiscoverySession
|
discoverySession session.DiscoverySession
|
||||||
|
@ -89,7 +53,10 @@ func Test_scanTCP(t *testing.T) {
|
||||||
name: "80",
|
name: "80",
|
||||||
args: args{
|
args: args{
|
||||||
discoverySession: s,
|
discoverySession: s,
|
||||||
targetPort: targetPort80,
|
targetPort: __test.Port(
|
||||||
|
targetHost,
|
||||||
|
"80",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
@ -97,7 +64,10 @@ func Test_scanTCP(t *testing.T) {
|
||||||
name: "139",
|
name: "139",
|
||||||
args: args{
|
args: args{
|
||||||
discoverySession: s,
|
discoverySession: s,
|
||||||
targetPort: targetPort139,
|
targetPort: __test.Port(
|
||||||
|
targetHost,
|
||||||
|
"139",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
@ -105,7 +75,10 @@ func Test_scanTCP(t *testing.T) {
|
||||||
name: "443",
|
name: "443",
|
||||||
args: args{
|
args: args{
|
||||||
discoverySession: s,
|
discoverySession: s,
|
||||||
targetPort: targetPort443,
|
targetPort: __test.Port(
|
||||||
|
targetHost,
|
||||||
|
"443",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
@ -113,7 +86,10 @@ func Test_scanTCP(t *testing.T) {
|
||||||
name: "445",
|
name: "445",
|
||||||
args: args{
|
args: args{
|
||||||
discoverySession: s,
|
discoverySession: s,
|
||||||
targetPort: targetPort445,
|
targetPort: __test.Port(
|
||||||
|
targetHost,
|
||||||
|
"445",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
@ -121,7 +97,10 @@ func Test_scanTCP(t *testing.T) {
|
||||||
name: "548",
|
name: "548",
|
||||||
args: args{
|
args: args{
|
||||||
discoverySession: s,
|
discoverySession: s,
|
||||||
targetPort: targetPort548,
|
targetPort: __test.Port(
|
||||||
|
targetHost,
|
||||||
|
"548",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
|
|
@ -35,7 +35,7 @@ func New() *ossw.Server {
|
||||||
sh.Name = "Probe"
|
sh.Name = "Probe"
|
||||||
sh.Services = services
|
sh.Services = services
|
||||||
|
|
||||||
sh.RegisterServlet("/", ss)
|
sh.RegisterServlet("/scanner", ss)
|
||||||
|
|
||||||
s := &ossw.Server{
|
s := &ossw.Server{
|
||||||
ServerHandler: sh,
|
ServerHandler: sh,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user