gpt4 book ai didi

shell - awk: hping: 打印 icmp 发起/接收之间的差异

转载 作者:行者123 更新时间:2023-12-04 16:17:52 28 4
gpt4 key购买 nike

我从 hping 得到以下输出在 OpenBSD 上:

# hping --icmp-ts www.openbsd.org
HPING www.openbsd.org (re0 129.128.5.194): icmp mode set, 28 headers + 0 data bytes
len=46 ip=129.128.5.194 ttl=237 id=23807 icmp_seq=0 rtt=155.3 ms
ICMP timestamp: Originate=22085077 Receive=22085171 Transmit=22085171
ICMP timestamp RTT tsrtt=156

len=46 ip=129.128.5.194 ttl=237 id=4150 icmp_seq=1 rtt=154.8 ms
ICMP timestamp: Originate=22086078 Receive=22086171 Transmit=22086171
ICMP timestamp RTT tsrtt=155

^C
--- www.openbsd.org hping statistic ---
2 packets tramitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 154.8/155.0/155.3 ms

我需要一些额外的算术 to troubleshoot asymmetric routes ,如 a patch in some bugreport 中提供,但我不想重新编译软件。

TL;DR,这两个新字段的计算方式为 Receive − OriginateOriginate + tsrtt − Transmit,结果如下(不一定需要跨越 4 行)。

len=46 ip=129.128.5.194 ttl=237 id=23807 icmp_seq=0 rtt=155.3 ms
ICMP timestamp: Originate=22085077 Receive=22085171 Transmit=22085171
ICMP timestamp RTT tsrtt=156 src->dst=94 dst->src=62

如何使用 awk 执行此操作? (我也可以使用任何其他 *BSD 工具。)

最佳答案

使用 perl,您可以执行以下操作:

#!/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";
}

如果您将此称为icmpstats.pl,则可以用作hping | perl icmpstats.pl.

关于shell - awk: hping: 打印 icmp 发起/接收之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20172028/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com