This commit is contained in:
crusader 2018-09-28 12:02:48 +09:00
parent 23ee90a233
commit 451f005f75
2 changed files with 9 additions and 10 deletions

View File

@ -16,9 +16,6 @@ import (
"github.com/google/gopacket/layers" "github.com/google/gopacket/layers"
) )
var totalCount = 0
var count = 0
func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) error { func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) error {
ps := discoverySession.PCapScanner() ps := discoverySession.PCapScanner()
if nil == ps { if nil == ps {
@ -28,13 +25,7 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
tcpChan := ps.OpenTCP(targetHost.Address) tcpChan := ps.OpenTCP(targetHost.Address)
defer func() { defer func() {
ps.CloseTCP(targetHost.Address, tcpChan) 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{}) timerStopped := make(chan struct{})
stopChan := make(chan struct{}) stopChan := make(chan struct{})
@ -46,6 +37,8 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
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 * 1000)
defer ticker.Stop()
for { for {
select { select {
case packet, ok := <-tcpChan: case packet, ok := <-tcpChan:
@ -58,7 +51,7 @@ 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) {
ticker.Stop() log.Print("SYN Timeout IP ", targetHost.Address)
timerStopped <- struct{}{} timerStopped <- struct{}{}
return return
} }
@ -128,6 +121,8 @@ 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)

View File

@ -128,6 +128,10 @@ func handlePacketTCP(ps *pCapScan, packet gopacket.Packet) {
layer := packet.Layer(layers.LayerTypeTCP) layer := packet.Layer(layers.LayerTypeTCP)
tcp, _ := layer.(*layers.TCP) tcp, _ := layer.(*layers.TCP)
if !tcp.SYN || !tcp.ACK {
return
}
ps.tcpListenerChanMtx.RLock() ps.tcpListenerChanMtx.RLock()
defer func() { defer func() {
ps.tcpListenerChanMtx.RUnlock() ps.tcpListenerChanMtx.RUnlock()