Pinging different IP address than what I entered

19

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

Example

Bob

Posted 2015-03-26T15:13:12.780

Reputation: 311

Question was closed 2015-03-31T07:58:07.067

This is a duplicate, I just can't remember where – Canadian Luke – 2015-03-26T16:09:08.030

@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 – 2015-03-27T14:06:38.870

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 – 2015-03-27T14:12:10.917

1As 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 – 2015-03-27T16:22:53.563

Answers

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

Posted 2015-03-26T15:13:12.780

Reputation: 15 868

2neat. did not know that. – Frank Thomas – 2015-03-26T16:03:37.207

3

Wow. That is a terrible undocumented "feature". Turns out Chrome does it also (4.4.4.8 and 4.4.4.010 are equivalent)

– Cole Johnson – 2015-03-26T17:58:20.750

3Well BEEP, it works with hex too! That makes the old ping 10.1000001 look almost sane... ping 10.0xDEAD ... !!! – user3710044 – 2015-03-26T19:17:34.753

38

It's neither terrible, nor undocumented; this is the regular notation for IPv4 addresses

– sleblanc – 2015-03-26T20:06:50.943

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 – 2015-03-27T02:44:42.173

3@trlkly so you're disappointed MS is following the standard? – Not loved – 2015-03-27T03:15:03.633

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 – 2015-03-27T04:01:32.070

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 – 2015-03-27T17:55:08.437

@phyrfox I suppose there's very little downside to accidentally pinging the wrong ip. And the ping tells you what it's pinging – Cruncher – 2015-03-27T21:12:18.427

4The 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 – 2015-03-27T22:15:45.557