2021-04-23 16:23:06 -05:00
|
|
|
import 'dart:io';
|
2020-07-27 15:43:58 -05:00
|
|
|
|
2022-09-21 15:27:35 -05:00
|
|
|
bool ipValidator(String? str, bool enableIPV6) {
|
|
|
|
if (str == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-23 16:23:06 -05:00
|
|
|
final ia = InternetAddress.tryParse(str);
|
|
|
|
if (ia == null) {
|
2020-07-27 15:43:58 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-23 16:23:06 -05:00
|
|
|
switch (ia.type) {
|
|
|
|
case InternetAddressType.IPv6:
|
|
|
|
{
|
|
|
|
if (enableIPV6) {
|
|
|
|
return true;
|
2021-05-03 16:58:04 -05:00
|
|
|
}
|
2021-04-23 16:23:06 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case InternetAddressType.IPv4:
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-27 15:43:58 -05:00
|
|
|
}
|
|
|
|
|
2021-04-23 16:23:06 -05:00
|
|
|
return false;
|
2020-07-27 15:43:58 -05:00
|
|
|
}
|