Wednesday, June 14, 2017

cheap bash script to monitor connections to an IP

this will trace only connections in the SYN_SENT status ... if you get a SocketTimeoutException, the connection will never transition in the ESTABLISHED state, it will only wait in the SYS_SENT state until it times out...

cat monitornet.sh

while true
do
     lines=`netstat -an | grep YOURDESTINATIONIP | grep SYN`
     sleep 0.1
     if [ "$lines" ]; then
         echo `date` $lines
         echo "   "
     fi
done




Maybe running netstat 10 times a second will kill your server, so you better sleep a bit more



No comments: