what process has a socket open

netstat -Aan|grep -v CLOSED|while read cb
do
    echo $cb | cut -d' ' -f1 | xargs -i rmsock {} tcpcb 2>/dev/null |
    perl -ne 'print $1,"\n" if /proccess (\d+)/' |
    xargs -i ps -fp {}|grep -v UID|
    awk '{printf "%s\t%s\t%s\n",$1,$2,$NF}'|
    sed -e "s|$|    $cb|"
done | awk '
BEGIN{
    tot=0;
    count[""]=0;
}{
    #print $0;
    tot++;
    count[$3]++;
}END{
    print "--------------------"
    for (i in count){
        if(i!="")print count[i], i;
    }
    print "--------------------"
    print tot, "total";
}'
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s