19

Can anyone please explain why CMD pings a different IP address than the one I am searching for?

Example

Bob
  • 311
  • 2
  • 5
  • This is a duplicate, I just can't remember where – Canadian Luke Mar 26 '15 at 16:09
  • @DavidPostill, It's not a duplicate, because in the question you linked to, the system was treating numbers with and without leading zeroes as decimal, but in this question, it's pretty clear the system is interpreting leading zeroes as octal numbers. – Sam Skuce Mar 27 '15 at 14:06
  • 3
    @SamSkuce Did you read the highest voted answer? "For example, if you use a 3-digit number starting with a zero (or a two-digit one starting with zero, ... ), then ping will assume the numbers are octal." – DavidPostill Mar 27 '15 at 14:12
  • 1
    As well, when we suggest a duplicate post, the OP is asked to look at the question *and answers* to see if it's the same – Canadian Luke Mar 27 '15 at 16:22

1 Answers1

45

On Windows CMD if you put leading zeros on the IP address means octal.

It is interpreting 016 as 16 octal and converts it to 14 decimal.

You can use octal, decimal or hexadecimal notation as in the following example:

22.101.31.153 (decimal)
026.0145.037.0231 (octal)
0x16.0x65.0xF1.0x99 (hexadecimal)
jcbermu
  • 17,278
  • 2
  • 52
  • 60
  • 2
    neat. did not know that. – Frank Thomas Mar 26 '15 at 16:03
  • 3
    Wow. That is a _terrible_ [undocumented "feature"](http://support.microsoft.com/kb/115388). Turns out Chrome does it also (`4.4.4.8` and `4.4.4.010` are equivalent) – Cole Tobin Mar 26 '15 at 17:58
  • 3
    Well BEEP, it works with hex too! That makes the old `ping 10.1000001` look almost sane... `ping 10.0xDEAD` ... !!! – user3710044 Mar 26 '15 at 19:17
  • 38
    It's neither terrible, nor undocumented; [this is the regular notation for IPv4 addresses](https://en.wikipedia.org/wiki/IPv4#Addressing) – sleblanc Mar 26 '15 at 20:06
  • 1
    @sebleblanc No, it's rather bad, since it differentiates between a leading zero and nothing, which a lot of implementations will not think to consider. It's a potential failure point with little upside, as octal is already rarely used--especially in this context. (Yes, the problem is with leading 0 octal notation in the first place, which should have been filtered out of modern languages, converted to something like leading 8x or something.) – trlkly Mar 27 '15 at 02:44
  • 3
    @trlkly so you're disappointed MS is following the standard? – undefined Mar 27 '15 at 03:15
  • 5
    @LukeMcGregor No. I think the standard itself is bad. I think leading 0 octal notation is bad. And while I'm glad Microsoft followed the standard, I'd prefer it be buried behind a switch for usability purposes, or at least some information being given to say that a specific number is being read as octal, and you should leave out the 0 if you don't want that. – trlkly Mar 27 '15 at 04:01
  • You can also skip zeroes. Try pinging 10.1, 192.168.1, and 127.1 (depending on your network, at least two of these should ping). I happened across this a while back, and it confused me briefly. I guess it's cool that we can do all kinds of shorthand, but I'd rather be forced to at least specify what I'm doing as intentional. – phyrfox Mar 27 '15 at 17:55
  • @phyrfox I suppose there's very little downside to accidentally pinging the wrong ip. And the ping tells you what it's pinging – Cruncher Mar 27 '15 at 21:12
  • 4
    The people handling IP addresses should understand what they are before using them. Leading zero octal notation is common enough that it is a mistake you will only do once. End users typically are not expected to handle IP addresses, or at least, they should not alter the representation. If the manual for your router says "connect to 172.16.0.1", you should not type in "172.016.000.001". – sleblanc Mar 27 '15 at 22:15