We had a need to ingest open sockets into Splunk so we could map our integration points across the enterprise. We came up with what is below. This will show if the host on which it is run is a client or a server of this socket, as well as print the IP address and port number of each side of the connection.
#!/bin/bash <