当我使用 hping3 时,我有以下输出:
hping3 -S -p 80 google.com HPING google.com (eth0 89.25.120.57): S
set, 40 headers + 0 data bytes
len=46 ip=89.25.120.57 ttl=62 id=40422 sport=80 flags=SA seq=0
win=29200 rtt=3.9 ms
len=46 ip=89.25.120.57 ttl=62 id=41026 sport=80 flags=SA seq=1
win=29200 rtt=7.8 ms len=46 ip=89.25.120.57 ttl=62 id=41341 sport=80
flags=SA seq=2 win=29200 rtt=3.7 ms ^C
--- google.com hping statistic --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 3.7/5.1/7.8 ms
我希望在每一行前面都加上日期:类似如何命令“Ping”显示 ping 的时间和日期
有人能帮忙吗 ?
答案1
我已让它发挥作用。
hping3 正在缓冲输出。因此,为了修复此问题,我在 Ubuntu 16.04 上安装了expect
( sudo apt-get install expect
),然后运行以下命令:
$ unbuffer hping3 -S -p 80 google.com | while read pong; do echo "$(date): $pong"; done
Wed Nov 2 12:48:29 UTC 2016: HPING google.com (ens160 172.217.23.14):
S set, 40 headers + 0 data bytes
Wed Nov 2 12:48:29 UTC 2016: len=46 ip=172.217.23.14 ttl=58 id=35798
sport=80 flags=SA seq=0 win=42900 rtt=7.9 ms
Wed Nov 2 12:48:30 UTC 2016: len=46 ip=172.217.23.14 ttl=58 id=44519
sport=80 flags=SA seq=1 win=42900 rtt=7.9 ms
Wed Nov 2 12:48:31 UTC 2016: len=46 ip=172.217.23.14 ttl=58 id=43418
sport=80 flags=SA seq=2 win=42900 rtt=3.8 ms
Wed Nov 2 12:48:32 UTC 2016: len=46 ip=172.217.23.14 ttl=58 id=9116
sport=80 flags=SA seq=3 win=42900 rtt=7.7 ms