gpt4 book ai didi

linux - Ping 并使用三个八位字节 ipv4 地址。为什么它有效?

转载 作者:IT王子 更新时间:2023-10-29 01:26:29 25 4
gpt4 key购买 nike

我不小心打错了字,发现我可以 ping 和 ssh 到 IP 地址 10.8.290 ... 正确的一个八位字节丢失了。有人可以向我解释吗?这是协议(protocol)的一部分还是某些 linux-black-magic(我使用的是 Debian)?

user@ws:~$ ping -c3 10.8.290
PING 10.8.290 (10.8.1.34) 56(84) bytes of data.
64 bytes from 10.8.1.34: icmp_req=1 ttl=62 time=0.910 ms
64 bytes from 10.8.1.34: icmp_req=2 ttl=62 time=0.686 ms
64 bytes from 10.8.1.34: icmp_req=3 ttl=62 time=0.708 ms

--- 10.8.290 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.686/0.768/0.910/0.100 ms
user@ws:~$ ssh root@10.8.290
The authenticity of host '10.8.290 (10.8.1.34)' can't be established.
ECDSA key fingerprint is 21:bd:7e:fb:1e:6d:1e:c1:e9:11:c0:a9:73:a8:cf:85.
Are you sure you want to continue connecting (yes/no)? no
Host key verification failed.

最佳答案

之所以有效,是因为您对 IP 地址的第三个字节使用了值 290。一个字节可以存储从 0255 的值,给出 256 值。由于 IPv4 地址是一个 4 字节值,将 290 传递到第三个字节会导致整数溢出到第 4 个字节 -> 290 - 256 => 34

它与协议(protocol)“功能” 无关。 ping 只是不验证 target 命令行参数的各个八位字节的值,只是将其传递给较低级别​​的 C 函数 inet_aton()(aton 表示 ascii 到数字)。这导致 ping 10.8.1.34

我不确定,但我希望其他版本的 ping(在 Windows、BSD 上)表现相同。

关于linux - Ping 并使用三个八位字节 ipv4 地址。为什么它有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28453052/

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