Guest User

Untitled

a guest
Jan 5th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.84 KB | None | 0 0
  1. r=; b=; e=; n=; compact=
  2.  
  3. for t in ${@}; do
  4.  
  5.     [ ${t} = usage   ] && { echo "   ${0} [color] [compact] [usage]"; exit 0; }
  6.     [ ${t} = color   ] && { r="\033[31;1m"; b="\033[34;1m"; e="\033[1m"; n="\033[0m"; }
  7.     [ ${t} = compact ] && compact=1
  8.  
  9. done
  10.  
  11. conn=$(lsof -i -F cnuLP)
  12.  
  13. cmd=; pid=; usr=; uid=; addr=; l_count=; count=0
  14.  
  15. for t in ${conn}; do
  16.  
  17.     case ${t:0:1} in
  18.         p)   pid=${t:1}; let count++; l_count=${count};;
  19.         c)   cmd=${t:1};;
  20.         u)   uid=${t:1};;
  21.         L)   usr=${t:1};;
  22.         P) proto=${t:1};;
  23.         n)  addr=${t:1}; [ ! -z ${compact} ] && mod="${r}->${n}${e}" || mod="\n\t${r}|${n}\n\t${e}"; addr="${addr/->/${mod}}";;
  24.     esac
  25.  
  26.     [ ! -z ${l_count} ] && printf "${l_count}: "; l_count=
  27.     [ ! -z ${usr}     ] && printf "${cmd} [${e}${pid}${n}] ${b}${usr}${n}:${e}${uid}${n}\n\n"; usr=
  28.     [ ! -z ${addr}    ] && printf "   ${b}${proto}${n}: ${addr}${n}\n\n"; addr=
  29.  
  30. done
Advertisement
Add Comment
Please, Sign In to add comment