frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

The lack of a good command line way to sort IPv6 addresses

https://utcc.utoronto.ca/~cks/space/blog/unix/SortingIPv6Addresses
13•zdw•7h ago

Comments

sargstuff•7h ago
IPv6 addresses are typically written in canonical text representation recommended by RFC 5952[0].

1) Regular expression / seamingly lost art of sprintf formatting are some methods to normalize 001:db8::2:1 to something usable for sorting aka 2001:db8:0000:0000:0000:0000:0002:0001. Perhaps restoring to rfc 5952 format when printing sorted results.

2) Modify hex to 'sortable utf-16 characters', modify back post sort[1]

3) avoid utf-8 / utf-16 issues, use relevant python libraries to handle ipv4/ipv6[2][3],[4]: ip2n < file | sort -n | n2ip

----------------------------

[0] : https://datatracker.ietf.org/doc/html/rfc5952

[1] : https://stackoverflow.com/questions/5797369/unix-sort-utilit...

[2] : https://stackoverflow.com/questions/75522231/how-to-sort-ipv...

[3] : https://www.geeksforgeeks.org/convert-ip-address-to-integer-...

[4] : https://ipfind.com/blog/how-to-convert-ip-address-to-integer...

0points•6h ago
1. Convert to numeric representation

2. Sort

3. Convert back

schoen•6h ago
Such a program in Python could be

  python3 -c 'import ipaddress, sys; print("\n".join(sorted(ipaddress.IPv6Address(x).exploded for x in sys.argv[1:])))'
It takes the IP addresses to be sorted on the command line.

Or, re-abbreviating them by removing zeroes and attempting to use :: where possible:

  python3 -c 'import ipaddress, sys; print("\n".join(str(ipaddress.IPv6Address(y)) for y in sorted(ipaddress.IPv6Address(x).exploded for x in sys.argv[1:])))'
Both of these versions will crash if given input that isn't syntactically valid as an IPv6 address.
fragmede•5h ago
It's ipv6. Seems like the "standard" thing to do would be to write and name a utility called sort6 which properly handles ipv6 addresses.
Gabrys1•5h ago
I imagine you wrote this sarcastically, but I do like this a lot!
ggm•5h ago
for all addresses, v4 and v6 this is what I used to do

  1) convert to a non-space-zeros-compressing hex string
  2) sort on the hex string
  3) convert back through inet_ntop()
Only a minor variant needed to deal with prefix/len sort order.
wpm•5h ago
Almost as if using hex values for IP addresses was a bad idea.
miyuru•5h ago
I don't think any IP version was made in with sorting as a feature, its just a by product of the representation.

This post also highlights a major thing I discovered when deploying and using IPv6, which is that you don't "Lift and shift" IPv4 to IPv6.

This is one of the reason its hard to deploy, because people cannot use the same IPv4 concepts to IPv6. For unknown reason they do, they will find the same problem they had with v4.

Telum II at Hot Chips 2024: Mainframe with a Unique Caching Strategy

https://chipsandcheese.com/p/telum-ii-at-hot-chips-2024-mainframe-with-a-unique-caching-strategy
18•rbanffy•1h ago•1 comments

Show HN: Every side project I've built since 2009

https://naeemnur.com/side-projects/
49•naeemnur•2h ago•13 comments

InventWood is about to mass-produce wood that's stronger than steel

https://techcrunch.com/2025/05/12/inventwood-is-about-to-mass-produce-wood-thats-stronger-than-steel/
138•LorenDB•23h ago•130 comments

Show HN: Goboscript, text-based programming language, compiles to Scratch

https://github.com/aspizu/goboscript
109•aspizu•5h ago•29 comments

Seagate claims spinning disks beat SSDs on carbon footprint

https://blocksandfiles.com/2025/04/16/seagate-decarbonizing-data-report/
34•rbanffy•2h ago•31 comments

Don't Guess My Language

https://vitonsky.net/blog/2025/05/17/language-detection/
101•e-topy•1h ago•69 comments

Emulator Debugging: Area 5150's Lake Effect

https://martypc.blogspot.com/2025/05/emulator-debugging-area-5150s-lake.html
21•rbanffy•2h ago•2 comments

New research reveals the strongest solar event ever detected, in 12350 BC

https://phys.org/news/2025-05-reveals-strongest-solar-event-bc.html
186•politelemon•3d ago•92 comments

Spaced repetition systems have gotten better

https://domenic.me/fsrs/
894•domenicd•23h ago•468 comments

“There are people who can see and others who cannot even look”

https://worldhistory.substack.com/p/there-are-people-who-can-see-and
153•crescit_eundo•11h ago•29 comments

Ditching Obsidian and building my own

https://amberwilliams.io/blogs/building-my-own-pkms
350•williamsss•19h ago•397 comments

Show HN: Sshsync – CLI tool to run shell commands across multiple remote servers

https://github.com/Blackmamoth/sshsync
23•blackmamoth•16h ago•30 comments

Llama from scratch (2023)

https://blog.briankitano.com/llama-from-scratch/
50•sebg•4d ago•0 comments

Programming in Martin-Lof's Type Theory: An Introduction (1990)

https://www.cse.chalmers.se/research/group/logic/book/
24•todsacerdoti•2d ago•0 comments

Show HN: I modeled the Voynich Manuscript with SBERT to test for structure

https://github.com/brianmg/voynich-nlp-analysis
345•brig90•19h ago•103 comments

Show HN: Job board aggregator for best paying remote SWE jobs in the U.S.

https://www.remoteswe.fyi
79•xitang•10h ago•53 comments

Layers All the Way Down: The Untold Story of Shader Compilation

https://moonside.games/posts/layers-all-the-way-down/
71•birdculture•8h ago•34 comments

'Significant amount' of private data stolen in UK Legal Aid hack

https://www.bbc.co.uk/news/articles/cgr5g4pv2l0o
4•neversaydie•14m ago•2 comments

France Endorses UN Open Source Principles

https://social.numerique.gouv.fr/@codegouvfr/114529954373492878
492•bzg•13h ago•149 comments

What do wealthy people buy, that ordinary people know nothing about? (2015)

https://old.reddit.com/r/AskReddit/comments/2s9u0s/comment/cnnmca8/
211•Tomte•19h ago•359 comments

Font Activations: A Note on the Type

https://robhorning.substack.com/p/font-activations
38•prismatic•2d ago•1 comments

Spaced Repetition Memory System

https://notes.andymatuschak.org/Spaced_repetition_memory_system
230•gasull•19h ago•27 comments

$30 Homebrew Automated Blinds Opener

https://sifter.org/~simon/journal/20240718.html
268•busymom0•18h ago•122 comments

Breaking the Sound Barrier Part I: Fuzzing CoreAudio with Mach Messages

https://googleprojectzero.blogspot.com/?m=0
5•weinzierl•2d ago•0 comments

K-Scale Labs: Open-source humanoid robots, built for developers

https://www.kscale.dev/
103•rbanffy•16h ago•46 comments

The Connoisseur of Desire

https://www.nybooks.com/articles/2025/05/29/the-connoisseur-of-desire-the-annotated-great-gatsby/
25•samclemens•2d ago•0 comments

Show HN: I reinvented PHP in TypeScript (demo)

https://github.com/vseplet/morph
11•vseplet•3d ago•7 comments

Show HN: A platform to find tech conferences, discounts, and ticket giveaways

https://www.tech.tickets/
82•danthebaker•2d ago•21 comments

Hyper Typing

https://pscanf.com/s/341/
87•azhenley•14h ago•61 comments

Mystical

https://suberic.net/~dmm/projects/mystical/README.html
402•mmphosis•1d ago•45 comments