A Tool to continually ‘ping’ TCP ports (nmap-ping)

What is TCP and the why use it?

TCP stands for Transmission Control Protocol. The purpose of TCP is to enable most data transmissions on the Internet or other computer network. TCP is very common.

TCP is the connection-based transmission of data. It provides a communication layer between the upper layers of the OSI model, such as the application layer, and the Internet Protocol layer. It guarantees delivery and correct transmission. For example, a data packet “A” and date packet “B” that are sent using TCP/IP will always be correctly assembled at the destination in the correct order.

Any use of the Internet Protocol can have unpredictable behaviour, data can be lost, duplicated, or delivered out of order. TCP can detect these kinds of issues. It can reorganise out of order data, request re-transmission from lost data.

Why would I need to perform a TCP Ping?

A port is a number used to uniquely identify a transaction over a network by specifying both the host and the service. They are necessary to differentiate between many different IP services, such as web service (HTTP), mail service (SMTP), and file transfer (FTP).

I occasionally find it useful to see whether the connection between myself and a target machine is on a stable net connection where the sys-admin has also blocked ICMP at their firewall.

The script

In order to monitor the uptime using just TCP ports I wrote this little script:

#!/bin/bash
if [ “$1” == “” ] || [ “$2” == “” ]; then
echo “Usage: `basename $0` {URL|IP} {TCP PORT} [DUBUG=false|true]”
else
INDEX=0
RESOLVED=`ping -q -c 1 -t 1 $1 | grep PING | awk {‘print $3’} | sed “s/[()]//g”`
echo “NMAP PING $1 ($RESOLVED)”
while [ 1==1 ]; do
INDEX=$((INDEX+1))
if [ “$3” == “true” ]; then
RESULT=`nmap -P0 -T5 -p$2 $RESOLVED –unprivileged`
else
RESULT=`nmap -P0 -T5 -p$2 $RESOLVED –unprivileged | grep “Host is up” | awk {‘print $4’} | sed ‘s/[^0-9\.]//g’`
fi
echo “Resp: $RESOLVED:$2/tcp Seq=$INDEX at $RESULT ms”
sleep 1
done
fi

This script can also be found in our GitHub repository here.

It is based on other peoples work (like the nmap project) and suggestions are welcome…

Lean how you can improve you cybersecurity

Contact us

This entry was posted in Useful Scripts & Applications. Bookmark the permalink.