ing
This commit is contained in:
parent
94609b4366
commit
d50a6608c0
|
@ -28,11 +28,18 @@ import (
|
||||||
// ZONE_MAC = "d0:7e:35:da:26:68"
|
// ZONE_MAC = "d0:7e:35:da:26:68"
|
||||||
// )
|
// )
|
||||||
|
|
||||||
|
// const (
|
||||||
|
// ZONE_NETWORK = "192.168.35"
|
||||||
|
// ZONE_IFACE = "\\Device\\NPF_{51459A06-A513-4202-9D79-93A4E394566A}"
|
||||||
|
// ZONE_ADDRESS = "179"
|
||||||
|
// ZONE_MAC = "08:00:27:f0:dc:35"
|
||||||
|
// )
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ZONE_NETWORK = "192.168.35"
|
ZONE_NETWORK = "192.168.1"
|
||||||
ZONE_IFACE = "\\Device\\NPF_{51459A06-A513-4202-9D79-93A4E394566A}"
|
ZONE_IFACE = "\\Device\\NPF_{9A232FAC-6AA4-48CE-AAC8-878ABFBFDA5D}"
|
||||||
ZONE_ADDRESS = "179"
|
ZONE_ADDRESS = "221"
|
||||||
ZONE_MAC = "08:00:27:f0:dc:35"
|
ZONE_MAC = "54-04-A6-38-BE-DA"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Zone() *omd.Zone {
|
func Zone() *omd.Zone {
|
||||||
|
|
|
@ -162,6 +162,7 @@ LOOP:
|
||||||
s := session.RetainDiscoverySession()
|
s := session.RetainDiscoverySession()
|
||||||
d.processingSessions.Store(req.RequestID(), s)
|
d.processingSessions.Store(req.RequestID(), s)
|
||||||
d.discover(req, s)
|
d.discover(req, s)
|
||||||
|
log.Print("Discover complete")
|
||||||
select {
|
select {
|
||||||
case <-time.After(time.Millisecond * 500):
|
case <-time.After(time.Millisecond * 500):
|
||||||
}
|
}
|
||||||
|
@ -171,6 +172,7 @@ LOOP:
|
||||||
d.processingSessions.Delete(req.RequestID())
|
d.processingSessions.Delete(req.RequestID())
|
||||||
s.Shutdown()
|
s.Shutdown()
|
||||||
}
|
}
|
||||||
|
log.Print("Discovery Session Shutdowm")
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-time.After(time.Millisecond * 500):
|
case <-time.After(time.Millisecond * 500):
|
||||||
|
@ -178,8 +180,8 @@ LOOP:
|
||||||
|
|
||||||
session.ReleaseDiscoverySession(s)
|
session.ReleaseDiscoverySession(s)
|
||||||
req.(*ofDiscoveryRequest).release()
|
req.(*ofDiscoveryRequest).release()
|
||||||
|
log.Print("Discovery complete")
|
||||||
|
|
||||||
log.Print("Discovery Session complete")
|
|
||||||
case <-d.stopChan:
|
case <-d.stopChan:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -285,19 +287,27 @@ func (d *ofDiscoverer) hierarchyDiscover(s session.DiscoverySession) {
|
||||||
case *omd.Host:
|
case *omd.Host:
|
||||||
d.SendMessage(s.DiscoveryRequest(), types.DiscoveryMessageTypeHost, target)
|
d.SendMessage(s.DiscoveryRequest(), types.DiscoveryMessageTypeHost, target)
|
||||||
if nil != s.DiscoverPort() {
|
if nil != s.DiscoverPort() {
|
||||||
|
h := target.(*omd.Host)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer func() {
|
||||||
port.Scan(s, target.(*omd.Host))
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
|
port.Scan(s, h)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
case *omd.Port:
|
case *omd.Port:
|
||||||
d.SendMessage(s.DiscoveryRequest(), types.DiscoveryMessageTypePort, target)
|
d.SendMessage(s.DiscoveryRequest(), types.DiscoveryMessageTypePort, target)
|
||||||
if nil != s.DiscoverService() {
|
if nil != s.DiscoverService() {
|
||||||
|
p := target.(*omd.Port)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer func() {
|
||||||
service.Scan(s, target.(*omd.Port))
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
|
service.Scan(s, p)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
case *omd.Service:
|
case *omd.Service:
|
||||||
|
@ -341,14 +351,18 @@ func (d *ofDiscoverer) hierarchyDiscover(s session.DiscoverySession) {
|
||||||
if nil != s.DiscoverHost() {
|
if nil != s.DiscoverHost() {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer func() {
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
host.Scan(s)
|
host.Scan(s)
|
||||||
}()
|
}()
|
||||||
} else if nil != s.DiscoverPort() {
|
} else if nil != s.DiscoverPort() {
|
||||||
if nil != s.Host() {
|
if nil != s.Host() {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer func() {
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
port.Scan(s, s.Host())
|
port.Scan(s, s.Host())
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -356,7 +370,9 @@ func (d *ofDiscoverer) hierarchyDiscover(s session.DiscoverySession) {
|
||||||
if nil != s.Port() {
|
if nil != s.Port() {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer func() {
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
service.Scan(s, s.Port())
|
service.Scan(s, s.Port())
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,17 +27,24 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
|
||||||
ps.CloseTCP(targetHost.Address, tcpChan)
|
ps.CloseTCP(targetHost.Address, tcpChan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
timerStopped := make(chan struct{})
|
timerStopped := make(chan struct{}, 0)
|
||||||
stopChan := make(chan struct{})
|
stopChan := make(chan struct{})
|
||||||
defer close(stopChan)
|
defer close(stopChan)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
defer func() {
|
||||||
|
close(timerStopped)
|
||||||
|
log.Print("timer close:", targetHost.Address)
|
||||||
|
}()
|
||||||
ports := make(map[int]*omd.Port)
|
ports := make(map[int]*omd.Port)
|
||||||
|
|
||||||
var delay atomic.Value
|
var delay atomic.Value
|
||||||
delay.Store(false)
|
delay.Store(false)
|
||||||
ticker := time.NewTicker(time.Millisecond * 1000)
|
ticker := time.NewTicker(time.Millisecond * 3000)
|
||||||
defer ticker.Stop()
|
defer func() {
|
||||||
|
ticker.Stop()
|
||||||
|
log.Print("ticker stop:", targetHost.Address)
|
||||||
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -51,8 +58,6 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
|
||||||
}
|
}
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if false == delay.Load().(bool) {
|
if false == delay.Load().(bool) {
|
||||||
log.Print("SYN Timeout IP ", targetHost.Address)
|
|
||||||
timerStopped <- struct{}{}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
delay.Store(false)
|
delay.Store(false)
|
||||||
|
@ -64,9 +69,11 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
|
||||||
log.Printf("sendTCP %v", err)
|
log.Printf("sendTCP %v", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
log.Print("sendTCP4 Complete:", targetHost.Address)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-timerStopped:
|
case <-timerStopped:
|
||||||
|
log.Print("timerStopped:", targetHost.Address)
|
||||||
return nil
|
return nil
|
||||||
case <-discoverySession.StopChan():
|
case <-discoverySession.StopChan():
|
||||||
return nil
|
return nil
|
||||||
|
@ -105,9 +112,10 @@ Loop:
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-time.After(time.Microsecond * 100):
|
// case <-time.After(time.Microsecond * 10):
|
||||||
case <-stopChan:
|
case <-stopChan:
|
||||||
return nil
|
return nil
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,8 +129,6 @@ func handlePacketTCP4(discoverySession session.DiscoverySession, host *omd.Host,
|
||||||
|
|
||||||
dp := discoverySession.DiscoverPort()
|
dp := discoverySession.DiscoverPort()
|
||||||
|
|
||||||
log.Print("SYN HandlePacket IP ", host.Address)
|
|
||||||
|
|
||||||
if packet.SYN && packet.ACK {
|
if packet.SYN && packet.ACK {
|
||||||
port := int(packet.SrcPort)
|
port := int(packet.SrcPort)
|
||||||
|
|
||||||
|
|
|
@ -21,13 +21,8 @@ func TestPing(t *testing.T) {
|
||||||
// )
|
// )
|
||||||
targetHost := __test.Host(
|
targetHost := __test.Host(
|
||||||
"",
|
"",
|
||||||
"179",
|
"1",
|
||||||
"08-00-27-F0-DC-35",
|
"00:11:32:7f:20:61",
|
||||||
)
|
|
||||||
|
|
||||||
targetPort := __test.Port(
|
|
||||||
targetHost,
|
|
||||||
139,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
|
@ -44,12 +39,31 @@ func TestPing(t *testing.T) {
|
||||||
name: "UNKNOWN",
|
name: "UNKNOWN",
|
||||||
args: args{
|
args: args{
|
||||||
service: __test.Service(
|
service: __test.Service(
|
||||||
targetPort,
|
__test.Port(
|
||||||
|
targetHost,
|
||||||
|
548,
|
||||||
|
),
|
||||||
omm.MetaCryptoTypeEnumNONE,
|
omm.MetaCryptoTypeEnumNONE,
|
||||||
"",
|
"",
|
||||||
),
|
),
|
||||||
pingOption: &ounp.PingOption{
|
pingOption: &ounp.PingOption{
|
||||||
Count: 3,
|
Count: 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "HTTP",
|
||||||
|
args: args{
|
||||||
|
service: __test.Service(
|
||||||
|
__test.Port(
|
||||||
|
targetHost,
|
||||||
|
5000,
|
||||||
|
),
|
||||||
|
omm.MetaCryptoTypeEnumNONE,
|
||||||
|
"HTTP",
|
||||||
|
),
|
||||||
|
pingOption: &ounp.PingOption{
|
||||||
|
Count: 5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user