
TCPing is a tool I developed while back, it allows you to use a TCP connection to ping a service. It can be used as a replacement of ICMP Ping in case the network doesn't allow ICMP, or as a service live check.
The tool also allows you to execute a command on each ping or when the status changes. And this is a useful feature to use for monitoring a service.
here I'll show you some examples on how to use this feature to expand the useablility of TCPing.
First lets see how TCPing work normally. To check the status of a service you only need the options -i for the hostname/IP and -p for the port.
for example, to check if a server is online or not, you can do the following:
tcping -i ayoob.ae -p 443
This will give the following results:
TCPing v0.2.1 (Beta)
Pinging IP address 188.166.136.202 on port 443
001. 2021-05-28T16:12:12 IP 188.166.136.202 on port 443 is online (0.131 Second)
002. 2021-05-28T16:12:13 IP 188.166.136.202 on port 443 is online (0.128 Second)
003. 2021-05-28T16:12:14 IP 188.166.136.202 on port 443 is online (0.137 Second)
004. 2021-05-28T16:12:15 IP 188.166.136.202 on port 443 is online (0.135 Second)
005. 2021-05-28T16:12:16 IP 188.166.136.202 on port 443 is online (0.128 Second)
Success: 5
Failed: 0
This is good when you want to do a quick check on the server, but what if you want to keep monitoring the server.
For that you can use the option --to-offline-cmd and --to-online-cmd. Those options allows you to execute a system command when the status of the server changes from offline to online and vice versa.
For example, lets assume you have a command to send an SMS, and the command is sms Phone_Number Message, you can call this command from TCPing to get an SMS notification when the server goes down.
tcping -i ayoob.ae -p 443 -n 0 --to-offline-cmd "sms +971501234567 'Server Down at {#DATE#}'"
If you notice here we've added the option -n and set it to 0. By defualt TCPing ping's the server 5 times then quits, with this option TCPing will ping the server until you stop the application. So if you want to run the application in the background you should use this option, but if you plane to use it in a Cron job, you should use the default.
Also you will notice the keyword {#DATE#}, this will be replaced with the timestamp of the ping request. There other variables that you can use in your command:
{#NO#} : Serial number of the ping id.
{#DATE#} : Time stamp of the ping.
{#IP#} : Target IP address.
{#PORT#} : Target Port.
{#STATUS#} : Status the server changed to (Online/Offline).
{#RESPONSE#} : Response time of the server.
With that being said, you can use this option to monitor any service and perform advanced tasks based on the status change.
For example you can trigger an API call using curl to submit a ticket in your IT ticketing system incase of server down. Or you can save the results in a database directly.
My advice, instead of writing a long command in the option --to-offline-cmd you can create a script (bash, python, powershell, etc...) and call the script name.
Example:-
tcping -i ayoob.ae -p 443 -q -n 0 --to-offline-cmd "python3 ~/bin/serverMonitor '{#NO#}' '{#DATE#}' '{#IP#}' '{#PORT#}' '{#STATUS#}' '{#RESPONSE#}'" --to-online-cmd "python3 ~/bin/serverMonitor '{#NO#}' '{#DATE#}' '{#IP#}' '{#PORT#}' '{#STATUS#}' '{#RESPONSE#}'"
With this TCPing will keep running and will pass the status to your python script each time the status changes, then your python script can do whatever task based on the information it gets from TCPing.
You can download TCPing v0.2.1 (Beta) from Github.
Also feel free submit an Issue in case you face any issue or need help.
| Name | Value |
|---|---|
| REMOTE_ADDR | 216.73.216.33 |
| HTTP_USER_AGENT | Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com) |
| REQUEST_METHOD | GET |
For more Information Click here.
| Snippet | |
|---|---|
| I just did a small Facelift for the website. | |
Released a new PHP class, easySQLite3 to secure the communication with SQLite3 Database. |
|
| Changing the chat box name to Communication Box for comments and questions. | |
| A message to someone: "As I said, you have my permission :P, have fun :D." | |
| Just for fun, I've added a chat box to my website, lets see how much spam I'm gonna get :P | |
| All articles from the old website has been moved to the new site. | |
| Added syntax highlighting for the codes in the Articles. | |
Today I've added a new application Snippets to write short snippets in the site. |
|
| I finally had the time to update the script of my site, the idea is a Desktop look. |