Say I want to know how many unique clients are connected to port 5222 on a server.
Can you find a way better/faster/stronger than this?
netstat -nt | grep ':5222.*ESTABLISHED' | awk '{ print $5 }' \
| grep -Po '[0-9]{1,3}(\.[0-9]{1,3}){3}' | uniq | wc -l
I know this is a too simple regex for a internet address, but seems unecessary to check for well formed addresses, as netstat will probably output only valid ones.
Can someone come to a netstat -nt | awk { awesomeness }
?
A netstat -nt | awk { simplicity }| uniq | wc -l
, maybe?