Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- COM=public
- # getting numbers of http, ftp, ssh, mysql from your host
- IP_HOST=`echo $@ | awk '{print $1}'`
- HTTP_CONNS=0
- FTP_CONNS=0
- SSH_CONNS=0
- MYSQL_CONNS=0
- OTHER_CONNS=0
- TOTAL_COUNT=0
- function get_port {
- local IFS='.'
- set $1
- LOCAL_PORT=$5
- echo $LOCAL_PORT
- return
- }
- # Call to snmpnetstat is at END of the loop to work around
- # silly bash scoping/while-loop issue.
- while read proto localip remote state ;
- do
- TOTAL_COUNT=$(($TOTAL_COUNT+1))
- LOCAL_PORT=`get_port $localip`
- # echo ">>> $proto $localip $remote $state $LOCAL_PORT"
- case "$LOCAL_PORT" in
- 22)
- SSH_CONNS=$(($SSH_CONNS+1))
- ;;
- 21)
- FTP_CONNS=$(($FTP_CONNS+1))
- ;;
- 80)
- HTTP_CONNS=$(($HTTP_CONNS+1))
- ;;
- 25)
- SMTP_CONNS=$(($SMTP_CONNS+1))
- ;;
- 3306)
- MYSQL_CONNS=$(($MYSQL_CONNS+1))
- ;;
- *)
- OTHER_CONNS=$(($OTHER_CONNS+1))
- ;;
- esac
- done < <(snmpnetstat -v2c -Cn -c $COM $IP_HOST | grep ^tcp )
- echo "http:$HTTP_CONNS ftp:$FTP_CONNS ssh:$SSH_CONNS mysql:$MYSQL_CONNS other:$OTHER_CONNS total:$TOTAL_COUNT"
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement