stripPort static method
a hop can carry a port: 1.2.3.4:5678 and [::1]:5678 become
1.2.3.4 and ::1. A bare IPv6 like ::1 has many :, so it stays.
Implementation
static String stripPort(String hop) {
if (hop.startsWith('[')) {
int end = hop.indexOf(']');
return end > 0 ? hop.substring(1, end) : hop;
}
int colon = hop.indexOf(':');
if (colon > 0 && colon == hop.lastIndexOf(':')) {
return hop.substring(0, colon);
}
return hop;
}