📜 ⬆️ ⬇️

Why ping to 192.168.072 returns a response from 192.168.0.58

If you make a typo in the IP-address, the result will be strange at first glance. For example, the ping to 192.168.72 is recognized as 192.168.0.72, and 192.168.072 is already recognized as 192.168.0.58.

People are overly complicating here because of the different RFCs, IP classes and the like. Just run a couple of tests and see how the ping command parses the incoming values.

ping
 C:\>ping 1 Pinging 0.0.0.1 with 32 bytes of data: C:\>ping 1.2 Pinging 1.0.0.2 with 32 bytes of data: C:\>ping 1.2.3 Pinging 1.2.0.3 with 32 bytes of data: C:\>ping 1.2.3.4 Pinging 1.2.3.4 with 32 bytes of data: C:\>ping 1.2.3.4.5 Ping request could not find host 1.2.3.4.5. Please check the name and try again. C:\>ping 255 Pinging 0.0.0.255 with 32 bytes of data: C:\>ping 256 Pinging 0.0.1.0 with 32 bytes of data: 

As it is easy to see, the ping command (in Windows) allows the use of different address formats. An IPv4 address can be split into four parts (octets): ABCD , and the ping command allows you not to specify all parts, filling in the gaps yourself using the following algorithm:
')
 1  (ping A) : 0.0.0.A 2  (ping AB) : A.0.0.B 3  (ping ABC) : AB0.C 4  (ping ABCD) : ABCD 

If you specify only one part, then it is perceived as an octet by the above algorithm. If it exceeds 255, then the value is converted and transferred to the next field.

There are several borderline cases. For example, if you specify more than four octets, then such an address is not recognized at all. So the google.com IP address will not work for either 0.74.125.226.4 or 74.125.226.4.0 .

You can use the hexadecimal form of the record as the division of octets by dots, and without division. In the first case, each octet must be preceded by the value 0x , in the second case, the prefix 0x indicated before the entire address. The octal system specifies the prefix 0 .

Thus, there are many ways to represent an IP address (IPv4). You can write it without dots or with dots (two dots, three dots or with one dot), and for each case you can use a different form of writing: decimal, hexadecimal, octal. They can even be mixed in the same address for different octets. For example, you can write the google.com address in the following ways:

google.com (domain name)
74.125.226.4 (decimal notation with dots)
1249763844 (decimal without points)
0112.0175.0342.0004 (octal with dots)
011237361004 (octal without dots)
0x4A.0x7D.0xE2.0x04 (hexadecimal with dots)
0x4A7DE204 (hex without dots)
74.0175.0xe2.4 (ಠ_ಠ)
(Thank God that the binary record is not supported yet!)

In our case, the ping to 192.168.072 uses the third option from the table above (AB0.C), so in reality the address is converted to 192.168.0.072. However, since the last octet starts from zero, it is treated as an octal value, which corresponds to 58 in the decimal system.

The riddle is solved.

It should be noted that although Windows ping supports such a variety of formats and correctly interprets them, this does not necessarily mean that these formats can be used everywhere. Some programs may require you to enter all four octets, others may prohibit mixing octal and decimal values ​​in one address, and so on.

Source: https://habr.com/ru/post/154695/


All Articles