Silly Little IP Tricks

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, March 22, 2015

Follow me on Twitter as @mattiasgeniar

I’ll show you a few things you can do with IP addresses you may not know yet. They aren’t new – just part of the RFC – but you don’t encounter them that often.

Octal values

For instance, did you know that if you prefix an IP address with 0’s, they get treated like Octal values? Spot the conversion in the ping below.

$ ping 193.239.211.036
PING 193.239.211.036 (193.239.211.30): 56 data bytes
Request timeout for icmp_seq 0
...

You would’ve expected the ping request to go to the IP ending in .36, instead if went to .30. Why? Because 036 is actually the octal value for the decimal 30.

Straight Up Integers

IP addresses are formed out of binary sequences, we know this. The binary forms get translate to decimals, for readability.

$ ping 3253719844
PING 3253719844 (193.239.211.36): 56 data bytes
64 bytes from 193.239.211.36: icmp_seq=0 ttl=57 time=17.003 ms
...

Pinging to an integer, like 3253719844, actually works. In the background, it’s converted to the real IP notation of 193.239.211.36.

Let’s Hex It

You probably saw this coming. If you can ping the integer notation of an IP, would the HEX value work?

$ ping 0xC1EFD324
PING 0xC1EFD324 (193.239.211.36): 56 data bytes
64 bytes from 193.239.211.36: icmp_seq=0 ttl=57 time=18.277 ms
...

Yup!

Skipping A Dot

A great addition thanks to Petru’s comment, is to skip a digit in the IP address.

$ ping 4.8
PING 4.8 (4.0.0.8): 56 data bytes
64 bytes from 4.0.0.8: icmp_seq=0 ttl=48 time=156.139 ms
...

The last digit-group is treated as the remainder of the values, so ping 4.8 actually expands to ping 4.0.0.8, because the digit ‘8’ is treated like a 48bit 24bit integer.

If you ever want to have fun with a junior colleague, think of these examples. Especially the octal values are very easy to miss, if you place the leading zeros somewhere in the middle.

Oh and if you decide to test these examples, you’ll be pinging one of our nameservers. No harm, feel free to.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.