TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

There’s more than one way to write an IP address

140 pointsby Mojahalmost 6 years ago

14 comments

Ididntdothisalmost 6 years ago
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.<p>After a while we noticed that a lot of them (around 30%) didn&#x27;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&#x27;t resolve through DNS but instead went straight to the (wrong) IP.<p>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&#x27;t get misinterpreted.
评论 #20391797 未加载
评论 #20391575 未加载
HocusLocusalmost 6 years ago
I did telephone tech support in an Austin boiler room for awhile and used the decimal IP notation I&#x27;d learned from my ISP days a lot. Sometimes accessing a customer&#x27;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.<p>Instead of directing them to 192.168.0.1 I&#x27;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.
评论 #20398070 未加载
jweatheralmost 6 years ago
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.
评论 #20391373 未加载
majkealmost 6 years ago
Parsing IPv6 also requires some thought! Consider 0000:0000:0001:0002:0000:0000:dead:beef<p>- 0000:0000:1:2::dead:beef<p>- ::1:2:0000:0000:dead:beef<p>- ::1:2:0:0:dead:beef<p>- ::1:2:0:0:222.173.190.239<p>- 0:0:1:2::222.173.190.239
评论 #20391820 未加载
评论 #20398604 未加载
dkerstenalmost 6 years ago
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 ;)
digitalsushialmost 6 years ago
I believe you can also represent an ipv4 address in base 10, by doing something like<p>a.b.c.d, (a * 2^24) + (b * 2^16) + (c * 2^8) + (d * 2^0)<p>(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)<p>The resultant number should be somewhere between 0 and (2^32)-1. It&#x27;s a neat toy. I&#x27;m not sure what value it has in practice.<p>192 x 2^24 + 168 x 2^16 + 0 x 2^8 + 1 x 2^0 == 3232235521<p>ping 3232235521 PING 3232235521 (192.168.0.1): 56 data bytes Request timeout for icmp_seq 0 ^C
评论 #20391515 未加载
评论 #20399669 未加载
siskalmost 6 years ago
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_lalmost 6 years ago
The bit with `ping 0` is sadly unexplored, as the nature of &quot;any host in network&quot; and &quot;any host in any network&quot; addresses are sadly unmentioned these days.<p>Then come the joys of debugging someone&#x27;s configuration because a tutorial told them to &quot;connect to 0.0.0.0&quot; instead of localhost...
评论 #20397398 未加载
luminatialmost 6 years ago
This was quite interesting thanks!<p>On a related note, does anyone have a good recommendations&#x2F;blog post that explains how IP addressing, ports, subnetting, etc. all work?<p>This is one of these things where I know that I&#x27;m just working off of empirical knowledge without knowing the fundamentals.
jakeoghalmost 6 years ago
Validation lib wip: <a href="https:&#x2F;&#x2F;github.com&#x2F;jakeogh&#x2F;hostname-validate&#x2F;blob&#x2F;master&#x2F;hostname_validate_regex_mono.py" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jakeogh&#x2F;hostname-validate&#x2F;blob&#x2F;master&#x2F;hos...</a>
lilyballalmost 6 years ago
What&#x27;s the explanation for why Linux treats 0.0.0.0 as 127.0.0.1?
评论 #20397613 未加载
评论 #20398495 未加载
评论 #20403069 未加载
corndogealmost 6 years ago
As documented in the man pages...<p><a href="https:&#x2F;&#x2F;www.freebsd.org&#x2F;cgi&#x2F;man.cgi?query=inet_pton" rel="nofollow">https:&#x2F;&#x2F;www.freebsd.org&#x2F;cgi&#x2F;man.cgi?query=inet_pton</a>
mehrdadnalmost 6 years ago
Wait, so does this mean 192.168&#x2F;16 means 192.0.0.168&#x2F;16 rather than 192.168.0.0&#x2F;16?
purplezooeyalmost 6 years ago
Octal notation. pshyeah