-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhping_parser.awk
66 lines (51 loc) · 2.11 KB
/
hping_parser.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright (C) 2021 Mark Baker mailto:[email protected] (github @Fail-Safe)
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#!/usr/bin/awk -f
# Set defaults for the record set
BEGIN {
RS = "len=[0-9]+ "
FS = " "
# Set an arbitrary high MIN value to compare against
min_uplink_time = min_downlink_time = 999999999
}
# This is to skip the "header" line from hping3 output. This replaces the previous 'tail -n+2' pipe.
NR == 1 { next }
# Main loop to iterate over each record in the record set
{
# RTT
rtt = $5
sub(/rtt=/, "", rtt) # Remove 'rtt=' from field
# Originate
orig = $9
sub(/Originate=/, "", orig) # Remove 'Originate=' from field
# Receive
rx = $10
sub(/Receive=/, "", rx) # Remove 'Receive=' from field
# Transmit
tx = $11
sub(/Transmit=/, "", tx) # Remove 'Transmit=' from field
# Calculate uplink and downlink times
uplink_time = rx - orig
downlink_time = orig + rtt - tx
# Evaluate if new MINs have been achieved
min_uplink_time = uplink_time < min_uplink_time ? uplink_time : min_uplink_time
min_downlink_time = downlink_time < min_downlink_time ? downlink_time : min_downlink_time
# Uncomment to get full hping3 output...
# print $0
# Uncomment to see record-by-record uplink and downlink timings...
# print uplink_time, downlink_time, min_uplink_time, min_downlink_time
}
# Final actions once record set has been iterated
END {
print min_uplink_time, min_downlink_time
}