Everybody is over-complicating it with RFCs, IP classes, and such. Simply run a few tests to see how the ping
command parses the IP input by the user (extraneous chaff removed):
> ping 1
Pinging 0.0.0.1 with 32 bytes of data:
> ping 1.2
Pinging 1.0.0.2 with 32 bytes of data:
> ping 1.2.3
Pinging 1.2.0.3 with 32 bytes of data:
> ping 1.2.3.4
Pinging 1.2.3.4 with 32 bytes of data:
> ping 1.2.3.4.5
Ping request could not find host 1.2.3.4.5. Please check the name and try again.
> ping 255
Pinging 0.0.0.255 with 32 bytes of data:
> ping 256
Pinging 0.0.1.0 with 32 bytes of data:
As you can see, the ping
command (in Windows) allows you to use different IP address formats. An IPv4 address can be broken down into four parts (“dotted-quad”) as so: A.B.C.D
, and the ping
command allows you to leave some out, filling in a default of 0
as follows:
1 part (ping A) : 0.0.0.A
2 parts (ping A.B) : A.0.0.B
3 parts (ping A.B.C) : A.B.0.C
4 parts (ping A.B.C.D) : A.B.C.D
If you only supply a single part, then if it is under 255 (the maximum for an octet), it is treated like an octet as above, but if it is greater than 255, then it is converted and rolled over into the next field (i.e., mod 256
).
There are a few edge cases like providing more than four parts doesn’t seem to work (e.g., pinging google.com
’s IP won’t work for either 0.74.125.226.4
or 74.125.226.4.0
).
You can also use hexadecimal notation in both dotted-quad and flat form, but must format it by pre-pending 0x
to each octet.
So, there are plenty of ways to represent an (IPv4) IP address. You can use flat or dotted-quad (or dotted-triple, dotted-double, or even dotted-single) format, and for each one, you can use (or even mix and match) decimal, octal, and hexadecimal. For example, you can ping google.com
in the following ways:
google.com
(domain name)
74.125.226.4
(dotted decimal)
1249763844
(flat decimal)
0112.0175.0342.0004
(dotted octal)
011237361004
(flat octal)
0x4A.0x7D.0xE2.0x04
(dotted hex)
0x4A7DE204
(flat hex)
74.0175.0xe2.4
(ಠ_ಠ)
(Thank goodness that binary notation support was not added!)
Application:
In your case, pinging 192.168.072
uses the third format in the above table (A.B.0.C
), so you are actually pinging 192.168.0.072
. Further, because you have a leading zero on the last part, it is treated as octal, which in decimal is 58.
Mystery solved.
Note, that while the Windows ping
command allows for such a wide variety of formats for the input and interprets non-standard formats in the ways seen, that does not necessarily mean that you can use such formats everywhere. Some programs may force you to provide all four parts of a dotted-quad, others may not allow mixing and matching decimal and octal, and so on.
Also, IPv6 addresses further complicate the parsing logic and input format acceptability.
Addendum:
syss pointed out that if you use an invalid character in one of the numbers (e.g., an 8
or 9
when using octal, a g
in hex-mode, etc.) then ping
is smart enough to recognize that and interpret it as a string(-al? -ic?) URL instead of as a numberic IP address.
(As someone who has had numerous aneurysms and heart-attacks trying to write supposedly “simple” code to accommodate the exponentially exploding number of permutations of data values, I appreciate that it—seems to—correctly process all of the input variations; in this case, at least 31+32+33+34=120 variations.)
So, while specifying 010.020.030.040
will ping 8.16.24.32
as expected, passing 010.020.030.080
to ping
will be treated like a URL instead of an IP address—like foo.bar.baz.com
which could (but sadly does not) exist. In other words, it tries to ping the subdomain 010
on the subdomain 020
on the domain 030
at the top-level domain 080
. However, since 080
is not a valid TLD (like .com
, .net
, and their buddies), the connection fails right at the first step.
The same thing happens with 090.010.010.010
where the invalid character is in a different octet. Likewise, 0xf.0xf.0xf.0xf
pings 15.15.15.15
, but 0xh1.0x1.0xg0.0f
fails.
Oh well, I guess that’s what you get for not being fluent in multiple number-bases.
It’s probably easier and safer to just make sure to always use 4–dotted-quad (“40q”? “quaddy-quad”? “cutie-q”?) addresses.
So go forth and learn some number bases. You’ll be able to show off at and be the life of parties, and as they say, there are 10 types of people: those who know binary and those who don’t.
Let’s not even think about IPv6 addresses; I think they’re one of the 111 seals!!!
9Relevant: http://blog.superuser.com/2012/02/10/wtfriday-http2915189091/ – Tamara Wijsman – 2012-10-12T17:27:05.987
2Interestingly, exactly the same thing happens on Linux:
ping 192.168.072
printsPING 192.168.072 (192.168.0.58) 56(84) bytes of data.
[...]. – Mechanical snail – 2012-10-12T18:43:29.9479what's even more random is that you had a machine at
192.168.0.58
to get a response. What are the odds of that? – James Mertz – 2012-10-12T20:27:46.6673@KronoS it's actually not so weird if you're on a school or company network. Some DHCP servers will give adresses in increasing order and most of them will be used. – Taum – 2012-10-12T22:38:09.313
1
Try loading http://1249739915/. In Chrome it translates to http://74.125.132.139, in Firefox it loads that URL. Related: http://php.net/ip2long
– Luc – 2012-10-12T23:06:42.993Firefox translates it for me actually and redirects to Google's home page. – Boris_yo – 2012-10-13T16:02:07.400
5
192.168.0.58
is timing out for me.. can all the ping requests have somehow knocked out the server?! – iamserious – 2012-10-16T09:19:47.1602@iamserious: That is the IP address on your local network (not the internet), if you don't have a PC with that IP address you won't get a response. – George Duckett – 2012-10-16T09:24:30.883