计算机网络实用工具之hping3

简介

hping3 是一个网络工具,能够发送自定义 ICMP/UDP/TCP 数据包并显示目标回复,就像 ping 对 ICMP 回复所做的那样。

它处理碎片和任意数据包主体和大小,并可用于在支持的协议下传输文件。使用 hping3,您可以测试防火墙规则、执行(欺骗)端口扫描、使用不同协议测试网络性能、进行路径 MTU 发现、在不同协议下执行类似路由跟踪的操作、指纹远程操作系统、审核 TCP/IP 堆栈等。

hping3 可以使用 Tcl 语言编写脚本。

官网

http://www.hping.org/

安装

# centos 7
[root@centos7 ~]# sudo yum install hping3

# ubuntu 22.04
root:~# sudo apt install hping3

使用帮助

root@:~# hping3 -h
usage: hping3 host [options]
  -h  --help      show this help
  -v  --version   show version
  -c  --count     packet count
  -i  --interval  wait (uX for X microseconds, for example -i u1000)
      --fast      alias for -i u10000 (10 packets for second)
      --faster    alias for -i u1000 (100 packets for second)
      --flood      sent packets as fast as possible. Don't show replies.
  -n  --numeric   numeric output
  -q  --quiet     quiet
  -I  --interface interface name (otherwise default routing interface)
  -V  --verbose   verbose mode
  -D  --debug     debugging info
  -z  --bind      bind ctrl+z to ttl           (default to dst port)
  -Z  --unbind    unbind ctrl+z
      --beep      beep for every matching packet received
Mode
  default mode     TCP
  -0  --rawip      RAW IP mode
  -1  --icmp       ICMP mode
  -2  --udp        UDP mode
  -8  --scan       SCAN mode.
                   Example: hping --scan 1-30,70-90 -S www.target.host
  -9  --listen     listen mode
IP
  -a  --spoof      spoof source address
  --rand-dest      random destionation address mode. see the man.
  --rand-source    random source address mode. see the man.
  -t  --ttl        ttl (default 64)
  -N  --id         id (default random)
  -W  --winid      use win* id byte ordering
  -r  --rel        relativize id field          (to estimate host traffic)
  -f  --frag       split packets in more frag.  (may pass weak acl)
  -x  --morefrag   set more fragments flag
  -y  --dontfrag   set don't fragment flag
  -g  --fragoff    set the fragment offset
  -m  --mtu        set virtual mtu, implies --frag if packet size > mtu
  -o  --tos        type of service (default 0x00), try --tos help
  -G  --rroute     includes RECORD_ROUTE option and display the route buffer
  --lsrr           loose source routing and record route
  --ssrr           strict source routing and record route
  -H  --ipproto    set the IP protocol field, only in RAW IP mode
ICMP
  -C  --icmptype   icmp type (default echo request)
  -K  --icmpcode   icmp code (default 0)
      --force-icmp send all icmp types (default send only supported types)
      --icmp-gw    set gateway address for ICMP redirect (default 0.0.0.0)
      --icmp-ts    Alias for --icmp --icmptype 13 (ICMP timestamp)
      --icmp-addr  Alias for --icmp --icmptype 17 (ICMP address subnet mask)
      --icmp-help  display help for others icmp options
UDP/TCP
  -s  --baseport   base source port             (default random)
  -p  --destport   [+][+]<port> destination port(default 0) ctrl+z inc/dec
  -k  --keep       keep still source port
  -w  --win        winsize (default 64)
  -O  --tcpoff     set fake tcp data offset     (instead of tcphdrlen / 4)
  -Q  --seqnum     shows only tcp sequence number
  -b  --badcksum   (try to) send packets with a bad IP checksum
                   many systems will fix the IP checksum sending the packet
                   so you'll get bad UDP/TCP checksum instead.
  -M  --setseq     set TCP sequence number
  -L  --setack     set TCP ack
  -F  --fin        set FIN flag
  -S  --syn        set SYN flag
  -R  --rst        set RST flag
  -P  --push       set PUSH flag
  -A  --ack        set ACK flag
  -U  --urg        set URG flag
  -X  --xmas       set X unused flag (0x40)
  -Y  --ymas       set Y unused flag (0x80)
  --tcpexitcode    use last tcp->th_flags as exit code
  --tcp-mss        enable the TCP MSS option with the given value
  --tcp-timestamp  enable the TCP timestamp option to guess the HZ/uptime
Common
  -d  --data       data size                    (default is 0)
  -E  --file       data from file
  -e  --sign       add 'signature'
  -j  --dump       dump packets in hex
  -J  --print      dump printable characters
  -B  --safe       enable 'safe' protocol
  -u  --end        tell you when --file reached EOF and prevent rewind
  -T  --traceroute traceroute mode              (implies --bind and --ttl 1)
  --tr-stop        Exit when receive the first not ICMP in traceroute mode
  --tr-keep-ttl    Keep the source TTL fixed, useful to monitor just one hop
  --tr-no-rtt       Don't calculate/show RTT information in traceroute mode
ARS packet description (new, unstable)
  --apd-send       Send the packet described with APD (see docs/APD.txt)

使用示例

# 使用traceroute模式(--traceroute), 显示详细信息(-V), ICMP(-1), 目票(www.google.com):
root@:~# hping3 --traceroute -V -1 www.google.com
using ens3, addr: 10.0.0.251, MTU: 9000
HPING www.google.com (ens3 172.217.26.228): icmp mode set, 28 headers + 0 data bytes
hop=1 TTL 0 during transit from ip=140.91.206.29 name=UNKNOWN
hop=1 hoprtt=3.8 ms
hop=2 TTL 0 during transit from ip=61.200.80.62 name=ae-0.oracle-oci.tokyjp10.jp.bb.gin.ntt.net
hop=2 hoprtt=3.7 ms
hop=3 TTL 0 during transit from ip=61.200.80.61 name=ae-33.a01.tokyjp10.jp.bb.gin.ntt.net
hop=3 hoprtt=3.4 ms
hop=4 TTL 0 during transit from ip=129.250.6.34 name=ae-5.r33.tokyjp05.jp.bb.gin.ntt.net
hop=4 hoprtt=3.3 ms
hop=5 TTL 0 during transit from ip=129.250.5.49 name=ae-7.a00.tokyjp09.jp.bb.gin.ntt.net
hop=5 hoprtt=3.1 ms
hop=6 TTL 0 during transit from ip=117.103.177.18 name=ae-0.google-tyo.tokyjp09.jp.bb.gin.ntt.net
hop=6 hoprtt=7.0 ms
hop=7 TTL 0 during transit from ip=209.85.143.41 name=UNKNOWN
hop=7 hoprtt=2.8 ms
hop=8 TTL 0 during transit from ip=142.250.61.69 name=UNKNOWN
hop=8 hoprtt=6.7 ms
len=42 ip=172.217.26.228 ttl=118 id=0 tos=0 iplen=28
icmp_seq=8 rtt=2.5 ms
len=42 ip=172.217.26.228 ttl=118 id=0 tos=0 iplen=28
icmp_seq=9 rtt=2.3 ms

种草

本文为"计算机网络实用工具系列"的内容之一,会持续更新其它相关博文。

我的博文内容主要针对“计算机网络”、“安全”、“运维”和“云计算”方向,感兴趣朋友的请关注我,我将不定期发布新的博文并不断改进已发布博文。

后期依据大家对博文的评论,点赞及关注情况,针对大家感兴趣的内容我也会录制视频并整理出成套的学习资料免费分享给大家,期待能和大家一起交流学习。

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hougang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值