this post was submitted on 15 Nov 2023
942 points (95.7% liked)

Programmer Humor

25620 readers
953 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] FauxPseudo@lemmy.world 294 points 2 years ago (9 children)

Ok. This covers every ipv6 and ipv4 address.

"^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:)))(%.+)?\s*$"

[–] YIj54yALOJxEsY20eU@lemm.ee 98 points 2 years ago

Lord have mercy

[–] dannym@lemmy.escapebigtech.info 76 points 2 years ago* (last edited 2 years ago) (1 children)

Please don't. Use regex to find something that looks like an IP then build a real parser. This is madness, its's extremely hard to read and a mistake is almost impossible to spot. Not to mention that it's slow.

Just parse [0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3} using regex (for v4) and then have some code check that all the octets are valid (and store the IP as a u32).

[–] Emma_Gold_Man@lemmy.dbzer0.com 8 points 2 years ago (1 children)

And dupe check. 0.0.0.0 and 000.000.000.000 may both be valid, but they resolve the same

[–] dannym@lemmy.escapebigtech.info 3 points 2 years ago* (last edited 2 years ago) (2 children)

Definitely, tho if you store it as a u32 that is fixed magically. Because 1.2.3.4 and 1.02.003.04 both map to the same number.

What I mean by storing it as a u32 is to convert it to a number, similar to how the IP gets sent over the wire, so for v4:

octet[3] | octet[2] << 8 | octet[1] << 16 | octet[0] << 24

or in more human terms:

(fourth octet) + (third octet * 256) + (second octet * 256^2) + (first octet * 256^3)
[–] Emma_Gold_Man@lemmy.dbzer0.com 2 points 2 years ago

True enough for database or dictionary storage, but a lot of times things get implemented in arrays where you still wind up with two copies of the same uint32.

[–] MsPenguinette@lemmy.world 49 points 2 years ago (5 children)

IPv6 was a mistake. We should have just added an addition octet

[–] Centillionaire@kbin.social 69 points 2 years ago (4 children)

That would allow for like, 2 trillion devices? Feels like a bandaid, my dude. Next you’re gonna suggest a giant ice cube in the ocean once a year to stop global warming.

[–] stoy@lemmy.zip 13 points 2 years ago (1 children)

So add two more octets:

Moat companies will still just use something like 10.0.13.37.0.1

[–] 0xD 11 points 2 years ago (2 children)

IPv6 is not made with internal networks in mind lol

[–] dan@upvote.au 1 points 2 years ago

You can use a ULA if you want to. That's essentially the IPv6 equivalent of a private IP.

Why though? Having the same IP for both internal and external solves a bunch of issues. For example, you don't need to use split horizon DNS any more (which is where a host name has a different IP on your internal network vs on the internet). You just need to ensure your firewalls are set up properly, which you should do anyways.

[–] stoy@lemmy.zip -2 points 2 years ago (1 children)

Never claimed it was, please quote me where I said as much

[–] dohpaz42@lemmy.world 17 points 2 years ago (1 children)

My dude, you used the 10.xx private IP as an example. Why wouldn’t they assume you were referring to internal networks?

[–] stoy@lemmy.zip -2 points 2 years ago (1 children)

I thought it was pretty clear with me adding 13.37 that I was making a joke, the earlier post spoke about how just adding one octet would still be too few addresses, so I joked about adding one more octet.

[–] dohpaz42@lemmy.world 3 points 2 years ago

I’m only pointing out why the other poster would make the assumption you were referring to an internal network. Do with it what you will.

[–] shasta@lemm.ee 8 points 2 years ago (1 children)
[–] intensely_human@lemm.ee 5 points 2 years ago (1 children)

Hurricanes cannot cross the equator. The equator is an imaginary line, and hence has zero mass. We can end every hurricane using zero point zero energy (0.0).

[–] jemikwa@lemmy.blahaj.zone 5 points 2 years ago (1 children)
[–] stringere@reddthat.com 2 points 2 years ago
[–] alienzx@feddit.nl 4 points 2 years ago* (last edited 2 years ago)

You could follow this logic and add 2 alphanumeric digits before 4 numeric octets. E.g. xf.192.168.1.1

This would at least keep it looking like an IP and not a Mac address. Another advantage would be graceful ipv4 handling with a reserved range starting with "ip" like ip.10.10.10.1

[–] Nalivai@discuss.tchncs.de 15 points 2 years ago (2 children)

Oh yeah, great, let's change the fundamental protocol on which all the networks in the world are based. Now two third of the devices in the world crashed because you tried to ping 192.168.0.0.1

[–] tilcica@lemm.ee 11 points 2 years ago

that WOULD be quite funny for the first second or 2....

[–] bjoern_tantau@swg-empire.de 4 points 2 years ago

Could have sped up adoption significantly.

[–] snor10@lemm.ee 5 points 2 years ago

They played us for absolute fools!

[–] FauxPseudo@lemmy.world 1 points 2 years ago

Plus the MAC address

[–] lnee@lemm.ee 1 points 2 years ago

IPv

heared of ipv5?

[–] SchizoDenji@lemm.ee 29 points 2 years ago

I knew there would be someone with the regex.

[–] BeigeAgenda@lemmy.ca 29 points 2 years ago

It's always a treat to debug a regex of that size.

[–] takeda@lemmy.world 18 points 2 years ago* (last edited 2 years ago)

You're more of a perl programmer than network engineer :P

[–] hemko@lemmy.dbzer0.com 4 points 2 years ago (1 children)
[–] 0x0@lemmy.dbzer0.com 2 points 2 years ago

Technically, this one also matches everything:

[–] shootwhatsmyname@lemm.ee 3 points 2 years ago* (last edited 2 years ago)

*exits the room*