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