Merge pull request #174 from gmkurtzer/expand_bracket

Bracket expansion for node ranges
This commit is contained in:
Gregory M. Kurtzer
2021-10-23 12:30:12 -07:00
committed by GitHub
16 changed files with 146 additions and 18 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"math/rand"
"net"
"os"
"os/exec"
"path"
@@ -368,3 +369,16 @@ func SplitValidPaths(input, delim string) []string {
return (ret)
}
func IncrementIPv4(start string, inc uint) string {
ip_start := net.ParseIP(start)
ipv4 := ip_start.To4()
v4_int := uint(ipv4[0])<<24 + uint(ipv4[1])<<16 + uint(ipv4[2])<<8 + uint(ipv4[3])
v4_int += inc
v4_o3 := byte(v4_int & 0xFF)
v4_o2 := byte((v4_int >> 8) & 0xFF)
v4_o1 := byte((v4_int >> 16) & 0xFF)
v4_o0 := byte((v4_int >> 24) & 0xFF)
ipv4_new := net.IPv4(v4_o0, v4_o1, v4_o2, v4_o3)
return ipv4_new.String()
}