2021-04-23 21:23:06 +00:00
|
|
|
import 'dart:io';
|
2020-07-27 20:43:58 +00:00
|
|
|
|
2021-04-23 21:23:06 +00:00
|
|
|
class IPAndPort {
|
2020-07-27 20:43:58 +00:00
|
|
|
String ip;
|
|
|
|
int port;
|
|
|
|
|
2021-04-23 21:23:06 +00:00
|
|
|
IPAndPort({this.ip, this.port});
|
|
|
|
|
2020-07-27 20:43:58 +00:00
|
|
|
@override
|
|
|
|
String toString() {
|
2021-04-23 21:23:06 +00:00
|
|
|
if (ip.contains(':')) {
|
|
|
|
return '[$ip]:$port';
|
|
|
|
}
|
|
|
|
|
2020-07-27 20:43:58 +00:00
|
|
|
return '$ip:$port';
|
|
|
|
}
|
|
|
|
|
|
|
|
String toJson() {
|
|
|
|
return toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
IPAndPort.fromString(String val) {
|
2021-04-23 21:23:06 +00:00
|
|
|
//TODO: Uri.parse is as close as I could get to parsing both ipv4 and v6 addresses with a port without bringing a whole mess of code into here
|
|
|
|
final uri = Uri.parse("ugh://$val");
|
|
|
|
this.ip = uri.host;
|
|
|
|
this.port = uri.port;
|
2020-07-27 20:43:58 +00:00
|
|
|
}
|
|
|
|
}
|