Check conncetion to AFP server through bash
To check if a connection to an AFP server - with the fixed listening port 548 - is established use:

netstat -naf inet | grep [.]548[\ ].*ESTAB*


or with quotes:

netstat -naf inet | grep '[.]548[\ ].*ESTAB*'


with -naf inet: no name resolution, all sockets and restrict to IPv4

and [.]548[\ ].*ESTAB* (grep for an) &lt;IP-address&gt;.548  ESTABLISHED. The [.] is required to exclude ports like 2548 or 10548. [\ ] excludes ports like 5480 or 5481. The .* concatenates everything (tab/spaces) between 548 and ESTAB*.

An example result looks like this:

tcp4       0      0  192.168.1.24.54340       192.168.1.2.548         ESTABLISHED


192.168.1.24 is the client's IP address and 192.168.1.2 the server's IP address then.