ing
This commit is contained in:
parent
dee29f34d9
commit
6f6d62f409
|
@ -47,13 +47,10 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
delay.Store(true)
|
delay.Store(true)
|
||||||
// go func(packet *layers.TCP) {
|
|
||||||
if p := handlePacketTCP4(discoverySession, targetHost, ports, packet); nil != p {
|
if p := handlePacketTCP4(discoverySession, targetHost, ports, packet); nil != p {
|
||||||
discoverySession.AddPort(p)
|
discoverySession.AddPort(p)
|
||||||
log.Print(p)
|
log.Print(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// }(packet)
|
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if false == delay.Load().(bool) {
|
if false == delay.Load().(bool) {
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package pcap
|
package pcap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/google/gopacket"
|
"github.com/google/gopacket"
|
||||||
"github.com/google/gopacket/layers"
|
"github.com/google/gopacket/layers"
|
||||||
)
|
)
|
||||||
|
@ -75,7 +77,11 @@ func handlePacketARP(ps *pCapScan, packet gopacket.Packet) {
|
||||||
arp := arpLayer.(*layers.ARP)
|
arp := arpLayer.(*layers.ARP)
|
||||||
|
|
||||||
for _, ch := range ps.arpListenerChans {
|
for _, ch := range ps.arpListenerChans {
|
||||||
ch <- arp
|
select {
|
||||||
|
case ch <- arp:
|
||||||
|
default:
|
||||||
|
log.Print("handlePacketARP cannot send to channel")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +93,11 @@ func handlePacketICMP4(ps *pCapScan, packet gopacket.Packet) {
|
||||||
// icmp4 := icmp4Layer.(*layers.ICMPv4)
|
// icmp4 := icmp4Layer.(*layers.ICMPv4)
|
||||||
|
|
||||||
for _, ch := range ps.icmp4ListenerChans {
|
for _, ch := range ps.icmp4ListenerChans {
|
||||||
ch <- packet
|
select {
|
||||||
|
case ch <- packet:
|
||||||
|
default:
|
||||||
|
log.Print("handlePacketICMP4 cannot send to channel")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +109,11 @@ func handlePacketICMP6(ps *pCapScan, packet gopacket.Packet) {
|
||||||
// icmp6 := icmp6Layer.(*layers.ICMPv6)
|
// icmp6 := icmp6Layer.(*layers.ICMPv6)
|
||||||
|
|
||||||
for _, ch := range ps.icmp6ListenerChans {
|
for _, ch := range ps.icmp6ListenerChans {
|
||||||
ch <- packet
|
select {
|
||||||
|
case ch <- packet:
|
||||||
|
default:
|
||||||
|
log.Print("handlePacketICMP6 cannot send to channel")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,16 +134,13 @@ func handlePacketTCP(ps *pCapScan, packet gopacket.Packet) {
|
||||||
|
|
||||||
chs, ok := ps.tcpListenerChans[ip]
|
chs, ok := ps.tcpListenerChans[ip]
|
||||||
if ok {
|
if ok {
|
||||||
// for _, ch := range chs {
|
|
||||||
// ch <- tcp
|
|
||||||
// }
|
|
||||||
for _, ch := range chs {
|
for _, ch := range chs {
|
||||||
select {
|
select {
|
||||||
case ch <- tcp:
|
case ch <- tcp:
|
||||||
default:
|
default:
|
||||||
|
log.Print("handlePacketTCP cannot send to channel")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +158,11 @@ func handlePacketUDP(ps *pCapScan, packet gopacket.Packet) {
|
||||||
chs, ok := ps.udpListenerChans[ip]
|
chs, ok := ps.udpListenerChans[ip]
|
||||||
if ok {
|
if ok {
|
||||||
for _, ch := range chs {
|
for _, ch := range chs {
|
||||||
ch <- packet
|
select {
|
||||||
|
case ch <- packet:
|
||||||
|
default:
|
||||||
|
log.Print("handlePacketUDP cannot send to channel")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,7 +191,7 @@ func (ps *pCapScan) OpenTCP(ip string) chan *layers.TCP {
|
||||||
ps.tcpListenerChans[ip] = make([]chan *layers.TCP, 0)
|
ps.tcpListenerChans[ip] = make([]chan *layers.TCP, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
ch := make(chan *layers.TCP, 1024)
|
ch := make(chan *layers.TCP, 2048)
|
||||||
ps.tcpListenerChans[ip] = append(ps.tcpListenerChans[ip], ch)
|
ps.tcpListenerChans[ip] = append(ps.tcpListenerChans[ip], ch)
|
||||||
|
|
||||||
return ch
|
return ch
|
||||||
|
@ -319,7 +319,7 @@ func handleReceive(ps *pCapScan) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case packet := <-inPacket:
|
case packet := <-inPacket:
|
||||||
go handlePacket(ps, packet)
|
handlePacket(ps, packet)
|
||||||
case <-ps.stopChan:
|
case <-ps.stopChan:
|
||||||
ps.destroy()
|
ps.destroy()
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user