ing
This commit is contained in:
parent
3579d26e52
commit
381a488709
|
@ -74,6 +74,7 @@ func (ps *pCapScan) start() error {
|
|||
h.Close()
|
||||
return err
|
||||
}
|
||||
ps.pCapHandle = h
|
||||
|
||||
ps.arpListenerChans = make([]chan *layers.ARP, 0)
|
||||
ps.tcpListenerChans = make(map[string][]chan *layers.TCP, 0)
|
||||
|
|
|
@ -32,6 +32,7 @@ func scanHost(zone *model.Zone, dh *model.DiscoveryHost, resultChan chan interfa
|
|||
}()
|
||||
|
||||
go func() {
|
||||
hosts := make(map[string]*model.Host)
|
||||
for {
|
||||
select {
|
||||
case packet, ok := <-arpChan:
|
||||
|
@ -39,12 +40,31 @@ func scanHost(zone *model.Zone, dh *model.DiscoveryHost, resultChan chan interfa
|
|||
logging.Logger().Debug(fmt.Sprintf("Discovery: arp channel is closed"))
|
||||
return
|
||||
}
|
||||
logging.Logger().Debug(fmt.Sprintf("Discovery: arp packet %v", packet))
|
||||
if h := handlePacketARP(zone, hosts, packet); nil != h {
|
||||
logging.Logger().Debug(fmt.Sprintf("Discovery: Host[%v] is founded", h))
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
time.Sleep(30 * time.Second)
|
||||
}
|
||||
|
||||
func handlePacketARP(zone *model.Zone, hosts map[string]*model.Host, packet *layers.ARP) *model.Host {
|
||||
// logging.Logger().Debug(fmt.Sprintf("Discovery: arp packet %v", packet))
|
||||
|
||||
ip := net.IP(packet.SourceProtAddress)
|
||||
if _, ok := hosts[ip.String()]; ok {
|
||||
return nil
|
||||
}
|
||||
h := &model.Host{}
|
||||
h.IP = ip.String()
|
||||
h.Mac = net.HardwareAddr(packet.SourceHwAddress).String()
|
||||
h.Zone = zone
|
||||
|
||||
hosts[ip.String()] = h
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
func sendARP(ps pcap.PCapScanner, zone *model.Zone, dh *model.DiscoveryHost) error {
|
||||
|
|
Loading…
Reference in New Issue
Block a user