check_ethernet: improve find_ssh_client for IPv6

This function had a number of problems:

(a) doesn't satisfy its description: it could print more than 1 IP,
    which its callers wouldn't really like
(b) it has this minor shellcheck warning:
    "SC1004: This backslash+linefeed is literal. Break outside single
     quotes if you just want to break the line."
(c) it only handles IPv4 properly (IPv6 has colons in the address, so we
    were only dumping the first hextet)

Fixes applied here:

 * netstat -l (listening) -- contradicts our search for "established"
 * netstat -p (program name) -- we ignore this
 * netstat -a (listening and non-listening) -- again, we're only looking
     for "established"
 * netstat -t -- add this, to limit the output netstat has to generate
 * netstat -W -- need wide printing, to fit IPv6 addresses
 * convert awk pattern to match columns more precisely, instead of a
     regex across the entire line
 * only look for the last colon when stripping the port (i.e.,
     dead:beef:...:22 -> dead:beef:...)
 * exit after the first match

Also, while netstat sort of gives us a time-ordered listing of
connections, it doesn't sort across different protocols (e.g., v4 vs.
v6). So just drop the "first" comment -- it's not really important to
the logic, as long as this finds some valid address.


Change-Id: I4d92d22572c5fd3bc8f85b97749a38cace8a0fb9
Tested-by: Brian Norris <>
Commit-Ready: Brian Norris <>
Legacy-Commit-Queue: Commit Bot <>
Reviewed-by: Grant Grundler <>
Reviewed-by: Alex Khouderchah <>
1 file changed