
There’s more than one way to write an IP address - Mojah
https://ma.ttias.be/theres-more-than-one-way-to-write-an-ip-address/
======
Ididntdothis
The different notations tripped us up big time a while ago at my company. A
class of our devices used to get their machine name set from the serial number
in the BIOS. On the older models these started with letters. Then we got a new
model and the serial numbers on these were just long numbers. So far so good.

After a while we noticed that a lot of them (around 30%) didn't work on the
network. It took a while to figure out that some of the serial numbers got
interpreted as octal IP addresses so pinging them didn't resolve through DNS
but instead went straight to the (wrong) IP.

In hindsight this could have been predicted but it just shows that often a
design that made sense when it was created can cause huge headaches later on.
Now we prefix all serial numbers with some letters to make sure they don't get
misinterpreted.

~~~
heavenlyblue
Why not base64 them?

Do you actually use serial numbers anywhere else?

Why not generate a random name instead?

~~~
Ididntdothis
The serial numbers are on the back of the devices so it’s nice to be able to
correlate them with the network name. As I mentioned now we prefix them with a
few letters to avoid being misinterpreted.

------
HocusLocus
I did telephone tech support in an Austin boiler room for awhile and used the
decimal IP notation I'd learned from my ISP days a lot. Sometimes accessing a
customer's router home page is a must and there is no connectivity for name
lookups. Elderly people have trouble with dots and numbers, or they add
spaces, or any number of things.

Instead of directing them to 192.168.0.1 I'd tell them to enter 3232235521 and
it would get the same place. My supervisor called me into the office because
someone heard me doing it while snooping a call and it freaked them out.

~~~
jpeeler
One character shorter, so that's somewhat helpful. However, wouldn't requiring
to type the [http://](http://) prefix still kill the simplification enough to
make this not even bothering with? Otherwise, both Chrome and Firefox will do
a google search for the decimal number.

~~~
inickt
You could just add a forward slash to the end of it instead of adding the
protocol, i.e. 3232235521/

------
jweather
I discovered the hard way that a library I was using would parse an IP address
in a URL like 192.168.000.077 as 192.168.0.63. Yeah... it treated leading
zeros as octal in individual components of the IP. Lots of fun to track down.

~~~
bluejekyll
It’s always annoyed me that IPv4 addresses are valid DNS names. Unnecessary
confusion and software workarounds to deal with it.

~~~
NikkiA
Back in the dark past of the late 1980s/early 1990s, "[x.x.x.x]" used to be a
convention to force parsing as an IP address rather than a DNS name. I have no
idea where this convention came from, or where it went to, but it seems to
have completely vanished since.

It's possible that it was a UK-specific convention that was borne from JANET
but I don't know; I do know that PAD and CPAD addresses (from X.25) were more
common on JANET than IP addresses, so that seems unlikely.

~~~
bluejekyll
This is a great point. Square brackets are still used in ipv6 to more easily
distinguish between the ip the port: e.g. [::1]:52

------
majke
Parsing IPv6 also requires some thought! Consider
0000:0000:0001:0002:0000:0000:dead:beef

\- 0000:0000:1:2::dead:beef

\- ::1:2:0000:0000:dead:beef

\- ::1:2:0:0:dead:beef

\- ::1:2:0:0:222.173.190.239

\- 0:0:1:2::222.173.190.239

~~~
majke
Digging more about IPv6 representation:

\- It's possible to stick "::" in many places

\- It's possible to have :0000: before or after "::"

\- leading zeros (:0001: is the same as :1:)

\- "Text Representation of Special Addresses", so the ::192.168.0.1
representation

\- hex uppercase vs hex lowercase

see [https://tools.ietf.org/html/rfc5952](https://tools.ietf.org/html/rfc5952)

~~~
Already__Taken
that rfc says upper/lower doesn't matter? Am I wrong?

~~~
deathanatos
That's the point: because it doesn't matter it provides two representations
for the same semantic thing.

~~~
jolmg
Well, that's just like IPv4, then. They can still be canonicalized, if you
need to compare them.

------
dkersten
I like the hex version better than the traditional version, although the
traditional one is easily recognised as an IP address, even without context,
so its probably best to stick with that ;)

------
digitalsushi
I believe you can also represent an ipv4 address in base 10, by doing
something like

a.b.c.d, (a * 2^24) + (b * 2^16) + (c * 2^8) + (d * 2^0)

(the first time i did this was the first time I understood raising a constant
to zero was one, so I left it there for myself)

The resultant number should be somewhere between 0 and (2^32)-1. It's a neat
toy. I'm not sure what value it has in practice.

192 x 2^24 + 168 x 2^16 + 0 x 2^8 + 1 x 2^0 == 3232235521

ping 3232235521 PING 3232235521 (192.168.0.1): 56 data bytes Request timeout
for icmp_seq 0 ^C

~~~
magmastonealex
I've used this a handful of times, actually!

I've mostly done it to determine a "next" IP address from a large range - i.e,
what IP comes after 10.0.0.255, and how can I bound it between 10.0.0.30 and
10.0.1.128?

It's much easier to increment an integer, compare it to other integers, and
then convert it back to an string-format IP than it is to implement those
operations by "parsing" IP addresses.

~~~
tomjakubowski
An IP address like 127.0.0.1 is an integer, written in an odd base 256
notation! What I think you mean is that it's easier to increment an integer
written in conventional base 10, because people are used to working with
numbers like that.

~~~
jolmg
I'm imagining magmastonealex found it useful for things like working with each
of 10.0.0.0/16 without having to manage the digits of those base-256 numbers:

    
    
      for (var i = 0; i < 2 ** 16; i++) {
        work("10.0." + i);
      }
    

as opposed to

    
    
      for (var i = 0; i < 2 ** 16; i++) {
        work("10.0." + i / 256 + "." + i % 256);
      }

------
sisk
There’s even more ways to skin this cat. Octal notation works (prefixed with a
0), and each octet can be represented differently (0x7F.1 == 0x7F.0.0.1 ==
127.0.0.1).

------
p_l
The bit with `ping 0` is sadly unexplored, as the nature of "any host in
network" and "any host in any network" addresses are sadly unmentioned these
days.

Then come the joys of debugging someone's configuration because a tutorial
told them to "connect to 0.0.0.0" instead of localhost...

~~~
MayeulC
As a side note, why wouldn't 0.0.0.0 be a valid address if you have a route
for it (just like you can set any public IP, and are not restricted to private
ranges)?

I recall setting 192.168.0.0 as a valid address in windows XP a while ago.

I usually find people in the networking are (especially teachers) to quite
stubbornly assume that things are always one way, while almost the entirety of
networking is comprised of RFCs.

Sure, default configurations help in that you don't have to change a device's
configuration, but I see no reason why I couldn't change my MAC, or set my
broadcast address to 10.0.0.42, or the broadcast MAC to 01:02:03:04:05:06, and
my gateway to 10.0.0.0 while I enjoy browsing the web on my 0.0.0.0-addressed
computer...

~~~
p_l
0.0.0.0 _is_ a valid address. You also have a route for 0.0.0.0/0, usually
called "default" :)

Just not valid for a host, as it is a _network_ address where "network" is
specified as _the whole internet_. It's how you create services listening to
connections from _any_ address - technically you can setup a listening socket
waiting for connections only from specific network, but I haven't tested it.

It's also why minimal _compliant_ IPv4 network has 4 IP addresses: the network
address, host 1, host 2, broadcast. There's an unratified RFC for allowing
only host 1 and host 2, but I believe it works only on some combinations of
gear/software.

Then of course you get systems accepting broken setups, like 192.168.0.0 host
address with /24 or /16 netmask.

However, 192.168.1.0/23 is a valid address a host can have.

------
luminati
This was quite interesting thanks!

On a related note, does anyone have a good recommendations/blog post that
explains how IP addressing, ports, subnetting, etc. all work?

This is one of these things where I know that I'm just working off of
empirical knowledge without knowing the fundamentals.

------
jakeogh
Validation lib wip: [https://github.com/jakeogh/hostname-
validate/blob/master/hos...](https://github.com/jakeogh/hostname-
validate/blob/master/hostname_validate_regex_mono.py)

------
eridius
What's the explanation for why Linux treats 0.0.0.0 as 127.0.0.1?

~~~
slivanes
When I bind a socket to 0.0.0.0 it means to all interfaces on the host
machine, of which 127.0.0.1 is one of those interfaces. Not sure if that
answers your question.

~~~
eridius
If you ping 0.0.0.0 on Linux it pings 127.0.0.1. That's the behavior I'm
talking about. Binding to 0.0.0.0 is something completely different and not
Linux-specific.

------
corndoge
As documented in the man pages...

[https://www.freebsd.org/cgi/man.cgi?query=inet_pton](https://www.freebsd.org/cgi/man.cgi?query=inet_pton)

------
mehrdadn
Wait, so does this mean 192.168/16 means 192.0.0.168/16 rather than
192.168.0.0/16?

------
purplezooey
Octal notation. pshyeah

