add dynamic IP attributions

This commit is contained in:
Xavier Henner
2019-07-10 19:00:52 +02:00
parent 88f5ac3765
commit 7418a70afc
3 changed files with 47 additions and 15 deletions

View File

@@ -1,6 +1,8 @@
package main
import (
"math/big"
"net"
"sort"
"github.com/pyke369/golang-support/uconfig"
@@ -32,3 +34,14 @@ func parseConfigArray(config *uconfig.UConfig, configpath string) []string {
}
return result
}
func nextIP(ip net.IP) net.IP {
// Convert to big.Int and increment
ipb := big.NewInt(0).SetBytes([]byte(ip))
ipb.Add(ipb, big.NewInt(1))
// Add leading zeros
b := ipb.Bytes()
b = append(make([]byte, len(ip)-len(b)), b...)
return net.IP(b)
}