IOS Style Output TCP connect() Pinger

There’s probably better ways to do this, ie. with hping3 or something, but this suits my needs right now.


Example output:



[[email protected] ~]$  sh tcpinger.sh 75 www.google.com 443 500
Sending 75, TCP connect() to www.google.com:443, timeout is 500 ms
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Success rate is 100.00 percent (75/75), response min/avg/max = 19.00/19.02/21.00 ms
[[email protected] ~]$ 

[[email protected] ~]$ sh tcpinger.sh 75 www.google.com 443 500
Sending 75, TCP connect() to www.google.com:443, timeout is 500 ms
!!!!!!!!!!!!!!!!!!!!……!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Success rate is 92.00 percent (69/75), response min/avg/max = 19.00/17.56/24.00 ms
#!/bin/bash COUNT=1 LINE_COUNT=1 LATENCY_TOTAL=0 LATENCY_MAX=0 LATENCY_MIN=32768 COUNT_LOSS=0 TIMEOUT=1000 if [ “x${4}” != “x” ] ; then   TIMEOUT=${4} fi echo “Sending ${1}, TCP connect() to ${2}:${3}, timeout is ${TIMEOUT} ms” while [ ${COUNT} -lt ${1} ] ; do    BLAH=`tcping –timeout ${TIMEOUT} –count 1 ${2} ${3} 2>&1 | grep OK`   if [ “x${BLAH}” != “x” ] ; then     echo -n ‘!’     LATENCY=`echo ${BLAH} | cut -f5 -d’ ‘ -`     LATENCY_TOTAL=`echo “scale=4; ${LATENCY_TOTAL} + ${LATENCY}” | bc`     if [ `echo “${LATENCY} < ${LATENCY_MIN}” | bc` -eq 1 ] ; then       LATENCY_MIN=${LATENCY}     fi     if [ `echo “${LATENCY} > ${LATENCY_MAX}” | bc` -eq 1 ] ; then       LATENCY_MAX=${LATENCY}     fi   else     echo -n ‘.’     COUNT_LOSS=$((${COUNT_LOSS} + 1))   fi   COUNT=$(( ${COUNT} + 1 ))   LINE_COUNT=$(( ${LINE_COUNT} + 1 ))   if [ ${LINE_COUNT} -gt 78 ] ; then     echo “”     LINE_COUNT=1   fi done LATENCY_AVERAGE=`echo “scale=2; ${LATENCY_TOTAL} / ${COUNT}” | bc` LOSS=`echo “scale=2; ${COUNT_LOSS} / ${COUNT} * 100” | bc` SUCCESS=`echo “scale=2; 100 – ${LOSS}” | bc` echo “” echo -n “Success rate is `printf ‘%02.2f’ ${SUCCESS}` percent ($((${COUNT} – ${COUNT_LOSS}))/${COUNT}), “ echo “response min/avg/max = `printf ‘%02.2f’ ${LATENCY_MIN}`/`printf ‘%02.2f’ ${LATENCY_AVERAGE}`/`printf ‘%02.2f’ ${LATENCY_MAX}` ms” # EOF
Author image
About colin-stubbs