ing
This commit is contained in:
parent
f01cb68527
commit
26da7a2e03
|
@ -154,9 +154,9 @@ func (d *defaultDiscoverer) innerDiscoverZone(wg *sync.WaitGroup, dataChan chan
|
||||||
if nil != dz.DiscoverHost {
|
if nil != dz.DiscoverHost {
|
||||||
cr, _ := cidr.NewCIDRRanger(z.Network)
|
cr, _ := cidr.NewCIDRRanger(z.Network)
|
||||||
dh := &ocmd.DiscoverHost{
|
dh := &ocmd.DiscoverHost{
|
||||||
FirstScanRange: cr.First().String(),
|
FirstScanRangeV4: cr.First().String(),
|
||||||
LastScanRange: cr.Last().String(),
|
LastScanRangeV4: cr.Last().String(),
|
||||||
DiscoverPort: dz.DiscoverHost.DiscoverPort,
|
DiscoverPort: dz.DiscoverHost.DiscoverPort,
|
||||||
}
|
}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go d.innerDiscoverHost(wg, dataChan, z, dh)
|
go d.innerDiscoverHost(wg, dataChan, z, dh)
|
||||||
|
|
|
@ -94,9 +94,9 @@ func sendARP(ps pcap.PCapScanner, zone *ocmd.Zone, hostRanges []net.IP, stopChan
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ip := net.ParseIP(zone.IP)
|
ip := net.ParseIP(zone.IPV4)
|
||||||
if nil == ip {
|
if nil == ip {
|
||||||
return fmt.Errorf("Discovery: IP(%s) of zone is not valid", zone.IP)
|
return fmt.Errorf("Discovery: IP(%s) of zone is not valid", zone.IPV4)
|
||||||
}
|
}
|
||||||
|
|
||||||
ethPacket := makePacketEthernet(hwAddr)
|
ethPacket := makePacketEthernet(hwAddr)
|
||||||
|
@ -146,7 +146,7 @@ func handlePacketARP(zone *ocmd.Zone, hostRanges []net.IP, hosts map[string]*ocm
|
||||||
}
|
}
|
||||||
|
|
||||||
h := &ocmd.Host{}
|
h := &ocmd.Host{}
|
||||||
h.IP = ip.String()
|
h.IPV4 = ip.String()
|
||||||
h.Mac = net.HardwareAddr(packet.SourceHwAddress).String()
|
h.Mac = net.HardwareAddr(packet.SourceHwAddress).String()
|
||||||
h.Zone = zone
|
h.Zone = zone
|
||||||
|
|
||||||
|
@ -157,22 +157,22 @@ func handlePacketARP(zone *ocmd.Zone, hostRanges []net.IP, hosts map[string]*ocm
|
||||||
|
|
||||||
func getTargetHostRange(dh *ocmd.DiscoverHost, cr cidr.CIDRRanger) ([]net.IP, error) {
|
func getTargetHostRange(dh *ocmd.DiscoverHost, cr cidr.CIDRRanger) ([]net.IP, error) {
|
||||||
var firstIP net.IP
|
var firstIP net.IP
|
||||||
if "" != dh.FirstScanRange {
|
if "" != dh.FirstScanRangeV4 {
|
||||||
firstIP = net.ParseIP(dh.FirstScanRange)
|
firstIP = net.ParseIP(dh.FirstScanRangeV4)
|
||||||
if nil == firstIP {
|
if nil == firstIP {
|
||||||
return nil, fmt.Errorf("Discovery: IP(%v) of FirstScanRange host is not valid", firstIP)
|
return nil, fmt.Errorf("Discovery: IP(%v) of FirstScanRange host is not valid", firstIP)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var lastIP net.IP
|
var lastIP net.IP
|
||||||
if "" != dh.LastScanRange {
|
if "" != dh.LastScanRangeV4 {
|
||||||
lastIP = net.ParseIP(dh.LastScanRange)
|
lastIP = net.ParseIP(dh.LastScanRangeV4)
|
||||||
if nil == lastIP {
|
if nil == lastIP {
|
||||||
return nil, fmt.Errorf("Discovery: IP(%v) of LastScanRange host is not valid", lastIP)
|
return nil, fmt.Errorf("Discovery: IP(%v) of LastScanRange host is not valid", lastIP)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
includeIPs := make([]net.IP, 0)
|
includeIPs := make([]net.IP, 0)
|
||||||
for _, iHost := range dh.IncludeHosts {
|
for _, iHost := range dh.IncludeHostsV4 {
|
||||||
iIP := net.ParseIP(iHost)
|
iIP := net.ParseIP(iHost)
|
||||||
if nil == iIP {
|
if nil == iIP {
|
||||||
return nil, fmt.Errorf("Discovery: IP(%v) of include host is not valid", iHost)
|
return nil, fmt.Errorf("Discovery: IP(%v) of include host is not valid", iHost)
|
||||||
|
@ -181,7 +181,7 @@ func getTargetHostRange(dh *ocmd.DiscoverHost, cr cidr.CIDRRanger) ([]net.IP, er
|
||||||
}
|
}
|
||||||
|
|
||||||
excludeIPs := make([]net.IP, 0)
|
excludeIPs := make([]net.IP, 0)
|
||||||
for _, eHost := range dh.ExcludeHosts {
|
for _, eHost := range dh.ExcludeHostsV4 {
|
||||||
eIP := net.ParseIP(eHost)
|
eIP := net.ParseIP(eHost)
|
||||||
if nil == eIP {
|
if nil == eIP {
|
||||||
return nil, fmt.Errorf("Discovery: IP(%v) of exclude host is not valid", eHost)
|
return nil, fmt.Errorf("Discovery: IP(%v) of exclude host is not valid", eHost)
|
||||||
|
|
|
@ -32,9 +32,9 @@ func scanPortTCP(host *ocmd.Host, dp *ocmd.DiscoverPort, resultChan chan interfa
|
||||||
go pcap.ReleaseScanner(host.Zone)
|
go pcap.ReleaseScanner(host.Zone)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
tcpChan := ps.OpenTCP(host.IP)
|
tcpChan := ps.OpenTCP(host.IPV4)
|
||||||
defer func() {
|
defer func() {
|
||||||
go ps.CloseTCP(host.IP, tcpChan)
|
go ps.CloseTCP(host.IPV4, tcpChan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
timerStopped := make(chan struct{})
|
timerStopped := make(chan struct{})
|
||||||
|
@ -133,7 +133,7 @@ func handlePacketTCP(host *ocmd.Host, dp *ocmd.DiscoverPort, ports map[int]*ocmd
|
||||||
}
|
}
|
||||||
|
|
||||||
port := int(packet.SrcPort)
|
port := int(packet.SrcPort)
|
||||||
logging.Logger().Debugf("Discovery: IP of TCP(%d) src %s", port, host.IP)
|
logging.Logger().Debugf("Discovery: IP of TCP(%d) src %s", port, host.IPV4)
|
||||||
|
|
||||||
if _, ok := ports[port]; ok || !dp.Contains(port) {
|
if _, ok := ports[port]; ok || !dp.Contains(port) {
|
||||||
return nil
|
return nil
|
||||||
|
@ -160,13 +160,13 @@ type PortPacketTCP struct {
|
||||||
func makePacketPortTCP(host *ocmd.Host) (*PortPacketTCP, error) {
|
func makePacketPortTCP(host *ocmd.Host) (*PortPacketTCP, error) {
|
||||||
packetTCP := &PortPacketTCP{}
|
packetTCP := &PortPacketTCP{}
|
||||||
|
|
||||||
srcIP := net.ParseIP(host.Zone.IP)
|
srcIP := net.ParseIP(host.Zone.IPV4)
|
||||||
if nil == srcIP {
|
if nil == srcIP {
|
||||||
return nil, fmt.Errorf("Discovery: IP(%s) of zone is not valid", host.Zone.IP)
|
return nil, fmt.Errorf("Discovery: IP(%s) of zone is not valid", host.Zone.IPV4)
|
||||||
}
|
}
|
||||||
dstIP := net.ParseIP(host.IP)
|
dstIP := net.ParseIP(host.IPV4)
|
||||||
if nil == dstIP {
|
if nil == dstIP {
|
||||||
return nil, fmt.Errorf("Discovery: IP(%s) of host is not valid", host.IP)
|
return nil, fmt.Errorf("Discovery: IP(%s) of host is not valid", host.IPV4)
|
||||||
}
|
}
|
||||||
|
|
||||||
packetTCP.IP = &layers.IPv4{
|
packetTCP.IP = &layers.IPv4{
|
||||||
|
|
|
@ -33,9 +33,9 @@ func scanPortUDP(host *ocmd.Host, dp *ocmd.DiscoverPort, resultChan chan interfa
|
||||||
pcap.ReleaseScanner(host.Zone)
|
pcap.ReleaseScanner(host.Zone)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
udpChan := ps.OpenUDP(host.IP)
|
udpChan := ps.OpenUDP(host.IPV4)
|
||||||
defer func() {
|
defer func() {
|
||||||
ps.CloseUDP(host.IP, udpChan)
|
ps.CloseUDP(host.IPV4, udpChan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
timerStopped := make(chan struct{})
|
timerStopped := make(chan struct{})
|
||||||
|
@ -84,9 +84,9 @@ func scanPortUDP(host *ocmd.Host, dp *ocmd.DiscoverPort, resultChan chan interfa
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendUDP(host *ocmd.Host, dp *ocmd.DiscoverPort, stopChan chan struct{}) error {
|
func sendUDP(host *ocmd.Host, dp *ocmd.DiscoverPort, stopChan chan struct{}) error {
|
||||||
ip := net.ParseIP(host.IP)
|
ip := net.ParseIP(host.IPV4)
|
||||||
if nil == ip {
|
if nil == ip {
|
||||||
return fmt.Errorf("Discovery: IP(%s) of host is not valid", host.IP)
|
return fmt.Errorf("Discovery: IP(%s) of host is not valid", host.IPV4)
|
||||||
}
|
}
|
||||||
|
|
||||||
ms := matcher.GetUDPMatchers()
|
ms := matcher.GetUDPMatchers()
|
||||||
|
@ -140,7 +140,7 @@ func sendUDP(host *ocmd.Host, dp *ocmd.DiscoverPort, stopChan chan struct{}) err
|
||||||
func handlePacketUDP(host *ocmd.Host, dp *ocmd.DiscoverPort, ports map[int]*ocmd.Port, packet gopacket.Packet) *ocmd.Port {
|
func handlePacketUDP(host *ocmd.Host, dp *ocmd.DiscoverPort, ports map[int]*ocmd.Port, packet gopacket.Packet) *ocmd.Port {
|
||||||
ipLayer := packet.Layer(layers.LayerTypeIPv4)
|
ipLayer := packet.Layer(layers.LayerTypeIPv4)
|
||||||
|
|
||||||
if ipLayer.(*layers.IPv4).SrcIP.String() == host.Zone.IP {
|
if ipLayer.(*layers.IPv4).SrcIP.String() == host.Zone.IPV4 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func scanServiceTCP(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) bool {
|
func scanServiceTCP(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) bool {
|
||||||
hostIP := port.Host.IP
|
hostIP := port.Host.IPV4
|
||||||
portNumber, err := cuej.NumberToInt(port.PortNumber)
|
portNumber, err := cuej.NumberToInt(port.PortNumber)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errChan <- fmt.Errorf("Discovery: Service scan on %s:%s error has occurred %v ", hostIP, port.PortNumber, err)
|
errChan <- fmt.Errorf("Discovery: Service scan on %s:%s error has occurred %v ", hostIP, port.PortNumber, err)
|
||||||
|
|
|
@ -17,7 +17,7 @@ func scanServiceUDP(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan i
|
||||||
}
|
}
|
||||||
|
|
||||||
ms := matcher.GetUDPMatchers()
|
ms := matcher.GetUDPMatchers()
|
||||||
mi := csm.NewMatchInfo(port.Host.IP, portNumber)
|
mi := csm.NewMatchInfo(port.Host.IPV4, portNumber)
|
||||||
|
|
||||||
for i := 0; i < len(ms); i++ {
|
for i := 0; i < len(ms); i++ {
|
||||||
m := ms[i]
|
m := ms[i]
|
||||||
|
|
|
@ -56,7 +56,7 @@ func scanZone(dz *ocmd.DiscoverZone, resultChan chan interface{}, errChan chan e
|
||||||
Network: ipnet.String(),
|
Network: ipnet.String(),
|
||||||
Iface: i.Name,
|
Iface: i.Name,
|
||||||
Mac: i.HardwareAddr.String(),
|
Mac: i.HardwareAddr.String(),
|
||||||
IP: strings.Split(addr.String(), "/")[0],
|
IPV4: strings.Split(addr.String(), "/")[0],
|
||||||
}
|
}
|
||||||
|
|
||||||
resultChan <- z
|
resultChan <- z
|
||||||
|
|
Loading…
Reference in New Issue
Block a user