Skip to content
Advertisement

Getting the exact ping in ms from the server [closed]

i’m having trouble trying to get the exact ping value in ms from the server and storing it. I’m trying to make a website that has colored boxes with the servers names, and it changes the colors depending on the ping. So i can know fast when the server is responding fast, slowly or when it’s down. I have been trying it on C#, but if there’s a more consistent way it doesn’t matter the language.

Advertisement

Answer

A simple bash do the job:

for i in www.google.com www.amazon.com www.microsoft.com
do
  echo "$i "`ping -4 -w 1 -c 1 $i | 
             perl -n -e 'print "$1n" if /time=([0-9.]+) ms/'`
done | 
gnuplot -e "
  set lmargin 10;
  set rmargin 10;
  set tmargin 5;
  set terminal png size 700,400;
  d = system('cat -');
  set print $d;
  print d;
  unset print;
  set output '/tmp/servers.ping.png';
  plot $d u 2 w lines notitle,
       $d u 0:2:1 w labels notitle
"

with output

enter image description here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement