isIP function
check if the string str
is IP version
4 or 6
version
is a String or anint
.
Implementation
bool isIP(String? str, {IPVersion version = IPVersion.any}) {
if (version == IPVersion.any) {
return isIP(str, version: IPVersion.ipV4) ||
isIP(str, version: IPVersion.ipV6);
} else if (version == IPVersion.ipV4) {
if (!_ipv4Maybe.hasMatch(str!)) {
return false;
}
final parts = str.split('.')..sort((a, b) => int.parse(a) - int.parse(b));
return int.parse(parts[3]) <= 255;
}
return version == IPVersion.ipV6 && _ipv6.hasMatch(str!);
}