How to use timestamp option in ping
I noticed that there is a timestamp option -T in the ping help. But I don't know how to use it.
I tried:
ping www.google.com -T
This is what I get:
Invalid timestamp type
What is the timestamp type and how do I use it?
Solution 1:
The -T
option is used to ask hops to insert the timestamp in the IP packets upon receiving the ping. It works by using the TS
option of IP packets, specified by RFC791.
ping -T
requires an argument: one of tsonly
, tsandaddr
or tsprespec
. You can read the manpage online or by running man ping
for more information on the usage.
Here's an example of usage:
$ ping -T tsandaddr 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(124) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=3.22 ms
TS: 192.168.1.3 63668917 absolute
192.168.1.1 534841740 absolute not-standard
192.168.1.1 1 not-standard
192.168.1.3 3
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=6.59 ms
TS: 192.168.1.3 63669919 absolute
192.168.1.1 534842745 absolute not-standard
192.168.1.1 0 not-standard
192.168.1.3 6
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=3.20 ms
TS: 192.168.1.3 63670920 absolute
192.168.1.1 534843743 absolute not-standard
192.168.1.1 1 not-standard
192.168.1.3 3
^C
--- 192.168.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 3.207/4.343/6.599/1.595 ms
Note that I've tried on my LAN. Some hops on the internet may reject IP packets with the timestamp option. (In fact, I cannot ping any internet host with -T
, probably my ISP is rejecting my packets.)
Solution 2:
Alternatively, if you want to log uptime of a link or host, you probably want a one-line response with a timestamp, eg:
ping -i 10 google.com | while read pong; do echo "$(date): $pong"; done
This will send a ping every ten seconds with -i 10
then pipe this to a file, eg add > /tmp/ping_google.log
. Output like:
Sat Jan 22 07:34:08 AEDT 2022: PING google.com (172.217.6.78) 56(84) bytes of data.
Sat Jan 22 07:34:08 AEDT 2022: 64 bytes from sfo07s17-in-f78.1e100.net (172.217.6.78): icmp_seq=1 ttl=118 time=2.27 ms
Sat Jan 22 07:34:18 AEDT 2022: 64 bytes from sfo07s17-in-f78.1e100.net (172.217.6.78): icmp_seq=2 ttl=118 time=1.32 ms
Sat Jan 22 07:34:28 AEDT 2022: 64 bytes from sfo07s17-in-f78.1e100.net (172.217.6.78): icmp_seq=3 ttl=118 time=1.34 ms
...
Hope this helps someone.