#!/bin/bash#tcp partport1=`netstat -an|grep LISTEN|egrep "0.0.0.0|:::"|awk '/^tcp/ {print $4}'|awk -F: '{print $2$4}'|sort -n`echo "TCP state:"echo "--------------------------------"echo "PORT PID COMMAND"for a in $port1dob=`lsof -n -i:$a|grep TCP|grep LISTEN|grep IPv4|awk '{printf("%d\t%s\n"),$2,$1}'`echo "$a $b"doneecho "--------------------------------"#udp partecho ""port2=`netstat -an|grep udp|awk '{print $4}'|awk -F: '{print $2}'|sed '/^$/d'|sort -n`echo "UDP state:"echo "--------------------------------"echo "PORT PID COMMAND"for a in $port2dob=`lsof -n -i:$a|grep UDP|grep IPv4|awk '{printf("%d\t%s\n"),$2,$1}'`if [ -n "$b" ];thenecho "$a $b"fidoneecho "--------------------------------"exit 0