Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.27 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. COM=public
  4.  
  5.  
  6. # getting numbers of http, ftp, ssh, mysql from your host
  7.  
  8. IP_HOST=`echo $@ | awk '{print $1}'`
  9.  
  10. HTTP_CONNS=0
  11. FTP_CONNS=0
  12. SSH_CONNS=0
  13. MYSQL_CONNS=0
  14. OTHER_CONNS=0
  15. TOTAL_COUNT=0
  16.  
  17. function get_port {
  18.     local IFS='.'
  19.     set $1
  20.     LOCAL_PORT=$5
  21.     echo $LOCAL_PORT
  22.     return
  23. }
  24.  
  25.  
  26. # Call to snmpnetstat is at END of the loop to work around
  27. # silly bash scoping/while-loop issue.
  28. while read proto localip remote state ;
  29. do
  30.  
  31.     TOTAL_COUNT=$(($TOTAL_COUNT+1))
  32.    
  33.    
  34.     LOCAL_PORT=`get_port $localip`
  35. #    echo ">>> $proto $localip $remote $state $LOCAL_PORT"
  36.  
  37.     case "$LOCAL_PORT" in
  38.    
  39.         22)
  40.             SSH_CONNS=$(($SSH_CONNS+1))
  41.             ;;
  42.  
  43.         21)
  44.             FTP_CONNS=$(($FTP_CONNS+1))
  45.             ;;
  46.  
  47.         80)
  48.             HTTP_CONNS=$(($HTTP_CONNS+1))
  49.             ;;
  50.  
  51.         25)
  52.             SMTP_CONNS=$(($SMTP_CONNS+1))
  53.             ;;
  54.  
  55.         3306)
  56.             MYSQL_CONNS=$(($MYSQL_CONNS+1))
  57.             ;;
  58.  
  59.         *)
  60.             OTHER_CONNS=$(($OTHER_CONNS+1))
  61.             ;;
  62.     esac
  63.    
  64. done < <(snmpnetstat -v2c -Cn -c $COM $IP_HOST | grep ^tcp )
  65.  
  66.  
  67. echo "http:$HTTP_CONNS ftp:$FTP_CONNS ssh:$SSH_CONNS mysql:$MYSQL_CONNS other:$OTHER_CONNS total:$TOTAL_COUNT"
  68.  
  69. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement