You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
504 B
Go
26 lines
504 B
Go
2 years ago
|
package netchecks
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net"
|
||
|
"reflect"
|
||
|
)
|
||
|
|
||
|
func IPNetIndexByIP(list []net.IPNet, ip net.IP) (int, error) {
|
||
|
for index, ipNetEntry := range list {
|
||
|
if ipNetEntry.Contains(ip) {
|
||
|
return index, nil
|
||
|
}
|
||
|
}
|
||
|
return -1, fmt.Errorf("ip not in ipNet-list")
|
||
|
}
|
||
|
|
||
|
func IPNetIndexByIPNet(list []net.IPNet, ipNet net.IPNet) (int, error) {
|
||
|
for index, ipNetEntry := range list {
|
||
|
if reflect.DeepEqual(ipNetEntry, ipNet) {
|
||
|
return index, nil
|
||
|
}
|
||
|
}
|
||
|
return -1, fmt.Errorf("ipNet not in ipNet-list")
|
||
|
}
|