#!/bin/bash

if [ $# -ne 1 ];then
    echo "Follow the one script name , one argument"
fi

case $1 in 

     LISTEN)
       netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' | grep $1 | awk '{print $2}'
        ;;

    SYN_RECV)
       netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' | grep $1 | awk '{print $2}'
        ;;

     SYN_SENT)
       netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' | grep $1 | awk '{print $2}'
        ;;

     ESTABLISHED)
       netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' | grep $1 | awk '{print $2}'
        ;;

     FIN_WAIT1)
       netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' | grep $1 | awk '{print $2}'
        ;;

     FIN_WAIT2)
       netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' | grep $1 | awk '{print $2}'
        ;;

     CLOSING)
       netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' | grep $1 | awk '{print $2}'
        ;;

     TIME_WAIT)
       netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' | grep $1 | awk '{print $2}'
        ;;
    *)
echo -e "\e[033mUsage: sh $0 [LISTEN|SYN_RECV|SYN_SENT|ESTABLISHED|FIN_WAIT1|FIN_WAIT2|CLOSING]\e[0m"
esac