Timestamps in a packet trace file can be tricky especially when the trace was collected on host A and you are looking at it on host B half way around the world. If you are trying to correlate a timestamp in a log file from host C the difficulty level goes up a notch. It is possible to correct for time zone differences but you need to be sure what the time zones are and even then sometimes it just doesn't seem to work correctly. If the times of both (or all three) systems have not been sync'ed correcting the time zone may not help. What I wanted to do was to insert a packet with the local time of host C displayed as text so that I could compare the time on the sending system with the time in the trace. However, for various reasons I could not use the Perl script How to make a trace file self documenting. I could however use ping so I wrote the following script.
Usage
ping-date.sh IP-ADDRESS SLEEP COUNT
Where:
IP-ADDRESS is the address or host name of the target of the ping. This host may not have anything to do with the problem for which you are collecting the trace. It doesn't even need to be answered since all we are really interested in is the data portion of the ping request
SLEEP Seconds between pings.
COUNT The number of pings to send. A count of 0 indicates that pings will be sent until the script is manually stopped. Standard Output is redirected to /dev/null.
Limitations
Figure 2 shows shows what it looks like when you run the script with a 0 count - basically, it loops forever. You can exit the loop with a control-C.
Examples
Figure 1 shows the message you get when you run the script with anything but 3 arguments
Figure 1
# sh ping-date.sh
Usage:
ping-date IP-ADDRESS SLEEP COUNT
IP-ADDRESS is the IP ADDRESS or host name of the target
SLEEP is the time in seconds between pings
COUNT number of pings to send, 0 means forever
Example:
ping-date 172.16.1.11 1 0
#
Figure 2
# sh ping-date.sh 172.16.1.11 1 0
# ping-date.sh # # usage # ping-date.sh IP-ADDRESS SLEEP COUNT # if [ $# -ne 3 ] then echo -e "Usage:\n\tping-date IP-ADDRESS SLEEP COUNT" echo -e "\t\tIP-ADDRESS is the IP ADDRESS or host name of the target" echo -e "\t\tSLEEP is the time in seconds between pings" echo -e "\t\tCOUNT number of pings to send, 0 means forever" echo -e "\t\tExample:" echo -e "\t\t ping-date 172.16.1.11 1 0" exit fi if [ $3 -eq 0 ] then while [ true ] do ping $1 -q -c 1 -p $(echo $(date | cut -c 5-20) | od -x | cut -c 9-47 | \ head -1 | awk '{print substr($1,3,2) substr($1,1,2) substr($2,3,2) \ substr($2,1,2) substr($3,3,2) substr($3,1,2) substr($4,3,2) \ substr($4,1,2) substr($5,3,2) substr($5,1,2) substr($6,3,2) \ substr($6,1,2) substr($7,3,2) substr($7,1,2) substr($8,3,2) \ substr($8,1,2)}') > /dev/null sleep $2 done else COUNT=0 while [ $COUNT -lt $3 ] do ping $1 -q -c 1 -p $(echo $(date | cut -c 5-20) | od -x | cut -c 9-47 | \ head -1 | awk '{print substr($1,3,2) substr($1,1,2) substr($2,3,2) \ substr($2,1,2) substr($3,3,2) substr($3,1,2) substr($4,3,2) \ substr($4,1,2) substr($5,3,2) substr($5,1,2) substr($6,3,2) \ substr($6,1,2) substr($7,3,2) substr($7,1,2) substr($8,3,2) \ substr($8,1,2)}') > /dev/null COUNT=$(($COUNT+1)) sleep $2 done fi |