Tim Mattison

Hardcore tech

Octal and Hexadecimal IP Addresses With Ping

| Comments

Have you ever seen a system print out an IP address like this?

1
Disconnected from 010.000.001.133

If you try to ping this IP address you’ll get quite interesting results. What the IP address should be is 10.0.1.133 but what ping reports that it is if you run the command with those leading zeroes included looks very odd.

1
2
3
timmattison$ ping 010.000.001.133
PING 010.000.001.133 (8.0.1.133): 56 data bytes
Request timeout for icmp_seq 0

See that 8.0.1.133 IP address that it is trying to reach? It turns out that if you put leading zeroes into an IP address that you pass to ping, and possibly other network tools, it treats those numbers as octal. Octal isn’t something most end-users deal with unless they’re reminiscing about their old Compuserve addresses.

In any case, if you find yourself trying to ping a machine with an IP address that has leading zeroes make sure you remove them!

This got me wondering what other weird things ping might do with IP addresses so I played around a bit and saw that it actually allows you to enter them in hex as well. This is useful for IPv6 but really strange for IPv4. Try it out and try to ping the above address with the first octet in hex:

1
2
timmattison$ ping 0xa.0.1.133
PING 0xa.0.1.133 (10.0.1.133): 56 data bytes

Sure enough it converts 0xa into 10. I’m not sure I’ll ever use that feature but its good to know what ping does to its input in the even that some other weird situation pops up.

Comments