This commit is contained in:
crusader 2017-11-16 20:31:48 +09:00
parent 3579d26e52
commit 381a488709
2 changed files with 23 additions and 2 deletions

View File

@ -74,6 +74,7 @@ func (ps *pCapScan) start() error {
h.Close() h.Close()
return err return err
} }
ps.pCapHandle = h
ps.arpListenerChans = make([]chan *layers.ARP, 0) ps.arpListenerChans = make([]chan *layers.ARP, 0)
ps.tcpListenerChans = make(map[string][]chan *layers.TCP, 0) ps.tcpListenerChans = make(map[string][]chan *layers.TCP, 0)

View File

@ -32,6 +32,7 @@ func scanHost(zone *model.Zone, dh *model.DiscoveryHost, resultChan chan interfa
}() }()
go func() { go func() {
hosts := make(map[string]*model.Host)
for { for {
select { select {
case packet, ok := <-arpChan: 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")) logging.Logger().Debug(fmt.Sprintf("Discovery: arp channel is closed"))
return 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 { func sendARP(ps pcap.PCapScanner, zone *model.Zone, dh *model.DiscoveryHost) error {