overflow_discovery/discovery/port.go

33 lines
825 B
Go
Raw Permalink Normal View History

2017-11-15 12:33:46 +00:00
package discovery
2017-11-18 08:23:39 +00:00
import (
"fmt"
"net"
2017-12-04 09:37:39 +00:00
discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model"
2017-11-18 08:23:39 +00:00
"git.loafle.net/overflow/overflow_discovery/discovery/ipv4"
"git.loafle.net/overflow/overflow_discovery/discovery/ipv6"
)
2017-11-15 12:33:46 +00:00
2017-12-04 09:37:39 +00:00
func scanPort(host *discoveryM.Host, dp *discoveryM.DiscoveryPort, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
2017-11-18 12:08:08 +00:00
defer func() {
doneChan <- struct{}{}
}()
2017-11-18 08:23:39 +00:00
_, ipNet, err := net.ParseCIDR(host.Zone.Network)
if nil != err {
errChan <- err
return
}
switch len(ipNet.IP) {
case net.IPv4len:
2017-11-18 12:08:08 +00:00
ipv4.ScanPort(host, dp, resultChan, errChan, stopChan)
2017-11-18 08:23:39 +00:00
case net.IPv6len:
2017-11-18 12:08:08 +00:00
ipv6.ScanPort(host, dp, resultChan, errChan, stopChan)
2017-11-18 08:23:39 +00:00
default:
errChan <- fmt.Errorf("Discovery: Not supported ip length")
return
}
2017-11-15 12:33:46 +00:00
}