Using TCPing as service monitor [Geeky]

head

TCPing

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.

If you have a question please use the Communication Box
Articles
 
 
Articles
Using TCPing as service monitor
easySQLite3 Secure Communication with SQLite3
777 Ninja Ransomware
Instagram Request over HTTP
PHP Static and Non Static Classes
URL fuzzing Attack and Protect
Slow boot in linux
Using Geany IDE instead of Arduino IDE
UAE Army Supporter
hack.chat and Brackets IDE
HTML Hider
Instagram Notification API
Risk in saving images from the web
Fake File Extension
Sending private files over Whatsapp
Holy Quraan Radio Software
Holy Quraan Radio
Path Disclosures in Error reporting
Directory Indexing
Trusting strangers with our passwords
Publicly posting an exploit
Whatsapp Remote Crash Vulnerability
Breathing Numbers Ribbon
The Love Auction
Run for Syria
The Amazing Soul
17°C
Breathing Numbers
 
 
LinkedIn
Github
@AyoobAli
Base64 Conversion
User Info
 
 
User Info
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.

Contact
 
 
Contact Card
E-Mail:    contact@Ayoob.ae

LinkedIn:  @AyoobAli
Twitter:   @AyoobAli
Github:    @AyoobAli
Snippets
 
 
Random Snippets
Date
Snippet
24-05-2021
I just did a small Facelift for the website.
11-04-2020
Released a new PHP class, easySQLite3 to secure the communication with SQLite3 Database.
08-03-2016
Changing the chat box name to Communication Box for comments and questions.
01-03-2016
A message to someone: "As I said, you have my permission :P, have fun :D."
29-02-2016
Just for fun, I've added a chat box to my website, lets see how much spam I'm gonna get :P
27-02-2016
All articles from the old website has been moved to the new site.
25-02-2016
Added syntax highlighting for the codes in the Articles.
25-02-2016
Today I've added a new application Snippets to write short snippets in the site.
24-02-2016
I finally had the time to update the script of my site, the idea is a Desktop look.
Notes
 
 
Private Notes


This application is private

Chat
 
 
Chat Box [Tripcode: nAst] Public