2
0

ip.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright © 2022 Ettore Di Giacinto <[email protected]>
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License along
  14. // with this program; if not, see <http://www.gnu.org/licenses/>.
  15. package utils
  16. import (
  17. "net"
  18. "sort"
  19. "github.com/c-robinson/iplib"
  20. )
  21. func NextIP(defaultIP string, ips []string) string {
  22. if len(ips) == 0 {
  23. return defaultIP
  24. }
  25. r := []net.IP{}
  26. for _, i := range ips {
  27. ip := net.ParseIP(i)
  28. r = append(r, ip)
  29. }
  30. sort.Sort(iplib.ByIP(r))
  31. last := r[len(r)-1]
  32. return iplib.NextIP(last).String()
  33. }