Hacker News new | past | comments | ask | show | jobs | submit login

... but please don't.



I use this to store IP addresses in a database because you can operate on numbers (e.g. WHERE subnet_start < $thisip < subnet_end) but hardly on the unique dotted format that we normally display them as.

Also to specify a bind address when I don't care, like running `php -S 0:3000` (the silly thing wants a bind address rather than only a port number. There, have one!) or accessing localhost in a browser (just typing 0:3000 is enough). For 127.0.0.1, unfortunately the best you can do is writing 127.1. The numeric, hex, and octal variants are 2130706433, 0x7f000001, and 017700000001, which I personally don't find preferable to 127.1.


If you're using a database, use something like Postgres that has this functionality built in[0]. You can store IPs, networks, etc. in a native format that has all sorts of functionality available out of the box.

[0] https://www.postgresql.org/docs/current/functions-net.html


Yes, storing is different from displaying though.

In MySQL for example, that's what INET_ATON() and INET_NTOA() are for, to convert between binary and display.

Analogous to storing timestamps but displaying as datetimes in a timezone.


This is why I love this site. I've been doing networking for many years and I'm not a total novice in databases, but I had no idea MySQL had these functions.



I'd still much rather store something that can be indexed in a btree than something where you have to always call a function on and do full table scans. Of course, before displaying to the user you'd use long2ip again (or the database equivalent you mentioned; I usually avoid doing unnecessary computations on the database and, instead, let the application handle display logic).


Sorry if I wasn't clear, I was agreeing with you! Yes precisely for indexing (plus just a fixed column size that wastes no space).


Obviously the octal and hex and overflow are pretty cursed, but I do like using 10.0.0.* for home IPv4 just 'cause typing ssh 10.1 is so darn convenient.


Or set up local DNS and search domains, or even just add entries to your hosts file. `ssh fw` is easy, as is `ssh server`, which while more characters are more in the central typing plane.


I have those too, but I'm familiar with all the IPs and I just got tired of adding DNS entries. Esp for some predictable ones in the "dynamic" range.

Also there are times I don't have DNS working. Often times at some console where copy/paste also isn't working or where I don't even have a mouse, and I extra appreciate the simpler typing :)


I switched to the 10/8 block at home because it's less stupid than typing 192.168.whatever for everything local. I'll have to try this.


I'm not convinced we shouldn't have (originally) adopted using pure hex, e.g. 0x7F000001 instead of 127.0.0.1. Personally, I think it makes subnet masks, etc, a lot _more_ obvious.


Yes. The nibble boundary is at every 4, not 8 bits too, making subetting A LOT easier.


I think the IP address libraries should only accept the standard dotted decimal octet form. And let the others die as non-standard, historical forms.


Next you'll tell me to stop visiting the alternate timeline where everyone has a mustache and domain names end in a period.

https://news.ycombinator.com./item?id=35751030 ;-)

( warning: your cookies for news.ycombinator.com won't work in news.ycombinator.com. )




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: