Linux HTTP -> Packet send delay time (ping)

Let's consider an example that will track the ping time when sending a packet to IP address, TCP port or Web site.

Required materials:

  • Computer: Any computer with a Linux operating system
  • Programs:
    • nano — command-line text editor
    • grep — command-line utility for searching plain-text data sets
    • cURL — command-line program for working with HTTP
    • hping3 – free packet generator and analyzer for TCP / IP, distributed by Salvatore Sanfilippo (also known as Antirez)
    • crontab — software utility used to periodically perform tasks at a specific time or interval.

Device adding and setting:

  1. Add a new device under the name of «Ping test» in VizIoT
  2. Let's configure the device parameters. Let's try to ping Google, IP address, IP port:
    1. tpgoogle key of «Milliseconds, ms» type;
    2. tpip key of «Milliseconds, ms» type;
    3. tpport key of «Milliseconds, ms» type;
  3. Copy pass key and access password in «Basic settings» of the device.

Setting up programs.

We will use «cURL» to send data, and we will use «hping3» to get data on the delay time for sending a packet.

Installing cURL and hping3.

  • On RedHat or CentOS:
    sudo yum install hping3 curl
  • On Debian, Ubuntu, or Linux Mint:
    sudo apt-get install hping3 curl

Let's look at the result of the command:

> hping3 -c 1 -S -1

In response, you will receive something like this:

HPING (ens33 icmp mode set, 28 headers + 0 data bytes
len=46 ip= ttl=128 id=16442 icmp_seq=0 rtt=15.1 ms

--- hping statistic ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 15.1/15.1/15.1 ms


Save command result:

res_ping_google=$(hping3 -c 1 -S -1 2>&1)

Check for the presence of the line "1 packets received" as it means that the packet was delivered successfully:

isOk=$(echo $res_ping_google | grep -Eo '1 packets received')

the default delay value will be 9999 ms, if the packet is delivered successfully, then we will pull out the average time from the result:

if [ "$isOk" == "1 packets received" ]
    time_ping_google=$(echo $res_ping_google | grep -Eo 'min/avg/max = [^ ]*' | grep -Eo '\/[^\/a-z]*\/' | grep -Eo '[^\/a-z]*')

We will use CURL to send HTTP GET requests. Example command with a request:

curl --silent "$time_ping_google" > /dev/null

Now let's write a script that will send information about the temperature of the processor and its cores to the server.

Script creation.

Let's create a script using a text editor:

nano /var/

Script content:

#Ping WEB site
res_ping_google=$(hping3 -c 1 -S -1 2>&1)
#Ping IP adress
res_ping_ip=$(hping3 -c 1 -S -1 2>&1)
#Ping TCP port
res_ping_port=$(hping3 -p 8080 -c 1 -S -1 2>&1)


isOk=$(echo $res_ping_google | grep -Eo '1 packets received')
if [ "$isOk" == "1 packets received" ]
	time_ping_google=$(echo $res_ping_google | grep -Eo 'min/avg/max = [^ ]*' | grep -Eo '\/[^\/a-z]*\/' | grep -Eo '[^\/a-z]*')

isOk=$(echo $res_ping_ip | grep -Eo '1 packets received')
if [ "$isOk" == "1 packets received" ]
	time_ping_ip=$(echo $res_ping_ip | grep -Eo 'min/avg/max = [^ ]*' | grep -Eo '\/[^\/a-z]*\/' | grep -Eo '[^\/a-z]*')

isOk=$(echo $res_ping_port | grep -Eo '1 packets received')
if [ "$isOk" == "1 packets received" ]
	time_ping_port=$(echo $res_ping_port | grep -Eo 'min/avg/max = [^ ]*' | grep -Eo '\/[^\/a-z]*\/' | grep -Eo '[^\/a-z]*')

#sending request
curl --silent "$key&pass=$pass&tpgoogle=$time_ping_google&tpip=$time_ping_ip&tpport=$time_ping_port" > /dev/null

Give the right to execute

> chmod +x /var/

We'll use the cron daemon to send every minute. Let's start the cron editor

> crontab -e

There must be such lines at the very beginning:


And at the very end, add a line that will run the script "/var/" every minute:

0-59 * * * * /var/

Adding widgets:

  1. Create a new dashboard under the name «PING testing»
  2. Add widgets «Ping TIME»
    • type: «Chart»;
    • device: «Ping test»;
    • parameter: tpgoogle , tpip , tpport

Now the setup is complete and you have to wait until your device connected to the server.