I have the following output from hping on OpenBSD:
# hping --icmp-ts www.openbsd.org
HPING www.openbsd.org (re0 129.128.5.194): icmp mode set, 28 headers + 0
Using perl, you can do something like this:
#!/usr/bin/perl -n
#
if (/Originate=(\d+) Receive=(\d+) Transmit=(\d+)/) {
($o, $r, $t) = ($1, $2, $3);
} elsif (/tsrtt=(\d+)/) {
print $r - $o, " ", $o + $1 - $t, "\n";
}
If you call this icmpstats.pl
, you can use as hping | perl icmpstats.pl
.
A modification of the solution from janos, to provide a usable snippet.
Note that the output of hping becomes fully buffered when redirected to a pipe, which, surprisingly, quite inhibits in the portability of the solution. See https://unix.stackexchange.com/questions/25372/turn-off-buffering-in-pipe and https://unix.stackexchange.com/questions/102403/turn-off-buffering-for-hping-in-openbsd.
The following works on OpenBSD, after installing the expect package:
unbuffer hping --icmp-ts ntp1.yycix.ca \
| perl -ne 'if (/icmp_seq=(\d+) rtt=(\d+\.\d)/) {($s, $p) = ($1, $2);} \
if (/ate=(\d+) Receive=(\d+) Transmit=(\d+)/) {($o, $r, $t) = ($1, $2, $3);} \
if (/tsrtt=(\d+)/) { \
print $s, "\t", $p, "\t", $1, " = ", $r - $o, " + ", $o + $1 - $t, "\n"; }'
The following is required on OS X, since its expect
is not accompanied by unbuffer
:
script -q /dev/null hping3 --icmp-ts ntp1.yycix.ca \
| perl -ne 'if (/icmp_seq=(\d+) rtt=(\d+\.\d)/) {($s, $p) = ($1, $2);} \
if (/ate=(\d+) Receive=(\d+) Transmit=(\d+)/) {($o, $r, $t) = ($1, $2, $3);} \
if (/tsrtt=(\d+)/) { \
print $s, "\t", $p, "\t", $1, " = ", $r - $o, " + ", $o + $1 - $t, "\r\n"; }'
This is a sample output form the script, which shows that the forward path is congested, and the return path is most likely not:
0 145.5 146 = 75 + 71
1 142.7 142 = 72 + 70
2 140.7 140 = 70 + 70
3 146.7 146 = 76 + 70
4 148.3 148 = 77 + 71
5 157.5 157 = 87 + 70
6 167.1 167 = 96 + 71
7 166.3 166 = 95 + 71
8 167.7 167 = 97 + 70
9 159.0 159 = 88 + 71
10 156.7 156 = 86 + 70
11 154.9 155 = 84 + 71
12 151.9 152 = 81 + 71
13 157.3 157 = 86 + 71
14 155.0 155 = 84 + 71
15 157.7 158 = 87 + 71
16 156.6 156 = 86 + 70
17 157.8 158 = 87 + 71
18 161.9 162 = 91 + 71
19 160.1 160 = 89 + 71
20 166.3 166 = 95 + 71
21 163.9 164 = 93 + 71
22 172.0 172 = 101 + 71
23 177.9 178 = 107 + 71
24 177.0 177 = 106 + 71
25 172.1 172 = 101 + 71
26 167.4 167 = 97 + 70
27 167.1 167 = 96 + 71
28 161.0 161 = 90 + 71
29 150.5 150 = 80 + 70
30 155.6 155 = 85 + 70
31 162.0 162 = 91 + 71
32 154.3 154 = 84 + 70
The following example is through the same path; notice how one value still goes up and down randomly, whereas the other one changes monotonically.
0 165.9 166 = -142113 + 142279
1 160.2 160 = -142118 + 142278
2 155.2 155 = -142122 + 142277
3 156.5 156 = -142121 + 142277
4 164.7 165 = -142112 + 142277
5 164.4 164 = -142111 + 142275
6 160.9 161 = -142114 + 142275
7 158.1 158 = -142117 + 142275
8 155.6 156 = -142119 + 142275
9 143.0 143 = -142131 + 142274
10 153.2 153 = -142120 + 142273
11 157.1 157 = -142115 + 142272
12 158.3 158 = -142114 + 142272
13 148.6 149 = -142123 + 142272
14 144.3 144 = -142127 + 142271
15 145.3 145 = -142125 + 142270
16 141.9 142 = -142128 + 142270