discoveryConfig added

This commit is contained in:
crusader 2018-08-30 20:40:21 +09:00
parent 6288478c89
commit af1a9f1eeb
4 changed files with 7 additions and 52 deletions

View File

@ -1,14 +1,12 @@
package discovery
import (
"fmt"
"net"
"git.loafle.net/commons/util-go/net/cidr"
"git.loafle.net/overflow/model/meta"
)
type DiscoverHost struct {
DiscoveryConfig *DiscoveryConfig `json:"discoveryConfig,omitempty"`
MetaIPType *meta.MetaIPType `json:"metaIPType,omitempty"`
FirstScanRange string `json:"firstScanRange,omitempty"`
@ -18,50 +16,3 @@ type DiscoverHost struct {
DiscoverPort *DiscoverPort `json:"discoverPort,omitempty"`
}
func (dh *DiscoverHost) TargetHosts(network string) ([]net.IP, error) {
cr, err := cidr.NewCIDRRanger(network)
if nil != err {
return nil, err
}
var firstIP net.IP
if "" != dh.FirstScanRange {
firstIP = net.ParseIP(dh.FirstScanRange)
if nil == firstIP {
return nil, fmt.Errorf("IP(%v) of FirstScanRange host is not valid", firstIP)
}
}
var lastIP net.IP
if "" != dh.LastScanRange {
lastIP = net.ParseIP(dh.LastScanRange)
if nil == lastIP {
return nil, fmt.Errorf("IP(%v) of LastScanRange host is not valid", lastIP)
}
}
includeIPs := make([]net.IP, 0)
for _, iHost := range dh.IncludeHosts {
iIP := net.ParseIP(iHost)
if nil == iIP {
return nil, fmt.Errorf("IP(%v) of include host is not valid", iHost)
}
includeIPs = append(includeIPs, iIP)
}
excludeIPs := make([]net.IP, 0)
for _, eHost := range dh.ExcludeHosts {
eIP := net.ParseIP(eHost)
if nil == eIP {
return nil, fmt.Errorf("IP(%v) of exclude host is not valid", eHost)
}
excludeIPs = append(excludeIPs, eIP)
}
ranges, err := cr.Ranges(firstIP, lastIP, includeIPs, excludeIPs)
if nil != err {
return nil, err
}
return ranges, nil
}

View File

@ -1,6 +1,8 @@
package discovery
type DiscoverPort struct {
DiscoveryConfig *DiscoveryConfig `json:"discoveryConfig,omitempty"`
FirstScanRange int `json:"firstScanRange,omitempty"`
LastScanRange int `json:"lastScanRange,omitempty"`
ExcludePorts []int `json:"excludePorts,omitempty"`

View File

@ -1,5 +1,7 @@
package discovery
type DiscoverService struct {
DiscoveryConfig *DiscoveryConfig `json:"discoveryConfig,omitempty"`
IncludeServices []string `json:"includeServices,omitempty"`
}

View File

@ -5,5 +5,5 @@ import (
)
type DiscoveryConfig struct {
Credentials credential.CredentialMap `json:"credentials,omitempty"`
Credentials credential.CredentialsMap `json:"credentials,omitempty"`
}