2017-11-15 12:09:38 +00:00
|
|
|
package discovery
|
|
|
|
|
2017-11-16 11:01:42 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
2017-11-15 12:33:46 +00:00
|
|
|
|
2017-11-16 11:01:42 +00:00
|
|
|
"git.loafle.net/overflow/overflow_discovery/api/module/discovery/model"
|
2017-11-17 15:12:38 +00:00
|
|
|
"git.loafle.net/overflow/overflow_discovery/discovery/ipv4"
|
|
|
|
"git.loafle.net/overflow/overflow_discovery/discovery/ipv6"
|
2017-11-16 11:01:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func scanHost(zone *model.Zone, dh *model.DiscoveryHost, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}) {
|
2017-11-17 15:12:38 +00:00
|
|
|
_, ipNet, err := net.ParseCIDR(zone.Network)
|
2017-11-17 10:46:56 +00:00
|
|
|
if nil != err {
|
|
|
|
errChan <- err
|
2017-11-17 15:12:38 +00:00
|
|
|
doneChan <- struct{}{}
|
2017-11-17 10:46:56 +00:00
|
|
|
return
|
|
|
|
}
|
2017-11-17 15:12:38 +00:00
|
|
|
switch len(ipNet.IP) {
|
|
|
|
case net.IPv4len:
|
|
|
|
ipv4.ScanHost(zone, dh, resultChan, errChan, doneChan)
|
|
|
|
case net.IPv6len:
|
|
|
|
ipv6.ScanHost(zone, dh, resultChan, errChan, doneChan)
|
2017-11-16 11:01:42 +00:00
|
|
|
|
2017-11-17 15:12:38 +00:00
|
|
|
default:
|
|
|
|
errChan <- fmt.Errorf("Discovery: Not supported ip length")
|
2017-11-16 11:01:42 +00:00
|
|
|
doneChan <- struct{}{}
|
2017-11-17 10:46:56 +00:00
|
|
|
return
|
|
|
|
}
|
2017-11-15 12:09:38 +00:00
|
|
|
}
|