I am using
netstat -lt | grep LISTEN to list all the tcp ports that are listening. I am supposed to use this data by my java application so I want to format the output in shell to reduce the processing overhead in Java. What I want is:
Protocol port status tcp 4567 LISTEN
type of output. Is there any way to achieve this using netstat or is there any other network applications provided by unix to do this ?
I also tried reading the services files by:
less /etc/services | grep tcp | cut -d '#' -f 1
but that way it will list all the tcp ports even though they are open or not. Any suggestion would be great!