Added function implementations to generate hosts by subnet and CIDR

This commit is contained in:
David J. Allen 2023-10-16 14:37:23 -06:00
parent 994bf07716
commit 555ecf679d
3 changed files with 92 additions and 6 deletions

View file

@ -16,6 +16,7 @@ var (
begin uint8
end uint8
subnets []string
subnetMasks []string
disableProbing bool
)
@ -28,8 +29,12 @@ var scanCmd = &cobra.Command{
if len(hosts) > 0 {
hostsToScan = hosts
} else {
for _, subnet := range subnets {
hostsToScan = append(hostsToScan, magellan.GenerateHosts(subnet, begin, end)...)
for i, subnet := range subnets {
if len(subnetMasks) > 0 {
hostsToScan = append(hostsToScan, magellan.GenerateHostsWithSubnet(subnet, subnetMasks[i])...)
} else {
hostsToScan = append(hostsToScan, magellan.GenerateHosts(subnet)...)
}
}
}
@ -63,9 +68,10 @@ var scanCmd = &cobra.Command{
func init() {
scanCmd.Flags().StringSliceVar(&hosts, "host", []string{}, "set additional hosts to scan")
scanCmd.Flags().IntSliceVar(&ports, "port", []int{}, "set the ports to scan")
scanCmd.Flags().Uint8Var(&begin, "begin", 0, "set the starting point for range of IP addresses")
scanCmd.Flags().Uint8Var(&end, "end", 255, "set the ending point for range of IP addresses")
// scanCmd.Flags().Uint8Var(&begin, "begin", 0, "set the starting point for range of IP addresses")
// scanCmd.Flags().Uint8Var(&end, "end", 255, "set the ending point for range of IP addresses")
scanCmd.Flags().StringSliceVar(&subnets, "subnet", []string{}, "set additional subnets")
scanCmd.Flags().StringSliceVar(&subnetMasks, "subnet-mask", []string{}, "set the subnet masks to use for network")
scanCmd.Flags().BoolVar(&disableProbing, "disable-probing", false, "disable probing scanned results for BMC nodes")
rootCmd.AddCommand(scanCmd)