310 points

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*$”

permalink
report
reply
106 points

Lord have mercy

permalink
report
parent
reply
83 points
*

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).

permalink
report
parent
reply
11 points

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

permalink
report
parent
reply
6 points

Fuck that, if for whatever reason I’m writing an IP validator by hand I’m disallowing leading zeros. Parsers are very inconsistent, some will parse 010 as 10, others as 0o10 == 8 (you can try that right now with a POSIX ping). Talk about a footgun.

permalink
report
parent
reply
3 points
*

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)
permalink
report
parent
reply
50 points

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

permalink
report
parent
reply
74 points

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.

permalink
report
parent
reply
13 points

So add two more octets:

Moat companies will still just use something like 10.0.13.37.0.1

permalink
report
parent
reply
9 points

And nuke the hurricanes

permalink
report
parent
reply
5 points

ONCE AND FOR ALL

permalink
report
parent
reply
4 points
*

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

permalink
report
parent
reply
17 points

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

permalink
report
parent
reply
12 points

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

permalink
report
parent
reply
4 points

Could have sped up adoption significantly.

permalink
report
parent
reply
6 points

They played us for absolute fools!

permalink
report
parent
reply
1 point

IPv

heared of ipv5?

permalink
report
parent
reply
1 point

Plus the MAC address

permalink
report
parent
reply
37 points
20 points
*

Made that joke in an interview once.

They didn’t think it was funny. They truly thought Regex was the solution to, but never the cause of, all problems.

They wanted to make a Regex to verify every single address in the world. Dodged a bullet

permalink
report
parent
reply
9 points
*

Holy hell yeah you did. How would you go about doing that in a single expression? A bunch of back references to figure out the country? What if that’s not included? Oy.

permalink
report
parent
reply
31 points

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

permalink
report
parent
reply
29 points

I knew there would be someone with the regex.

permalink
report
parent
reply
18 points
*

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

permalink
report
parent
reply
4 points

.*

permalink
report
parent
reply

Technically, this one also matches everything:

permalink
report
parent
reply
3 points
*

*exits the room*

permalink
report
parent
reply
177 points

0.0.0.0/0 0::0/0

You didn’t specify it couldn’t be in CIDR block notation…

permalink
report
reply
26 points

::/0

permalink
report
parent
reply
7 points

Remember, when we abbreviate an ipv6 address all leading zeros are reduced to a single 0.

E.g

0003 would just become 03

When there are geoups of 4 zeros these can be represented as a single 0 or as a double colon ::

But we can only use the :: once so when summarizing an address containing multiple groups of 4 0s one after the other they can all be abbreviated to a single ::

Eg

fe80:0000:0000:0000:0210:5aff:feaa:20a2 would become fe80::210:5aff:feaa:20a2

Therefore it is perfectly valid to abbreviate an address of 0000:0000:0000:0000:0000:0000:0000:0000 /0 to just ::/0

permalink
report
parent
reply
2 points

Eh, I’ve seen some software internally prefer 0::0 instead of just ::0 or :: . Notation wise though you are correct, it is unnecessary.

permalink
report
parent
reply
91 points

0.0.0.0 /0 ::/0

SUCK MY DICK, GRU!

permalink
report
reply
4 points

Haha spot on

permalink
report
parent
reply
1 point

This is the way.

permalink
report
parent
reply
1 point
Deleted by creator
permalink
report
parent
reply
2 points

Its CIDR notation. So /0 means the subnet mask has no on bits and would read as 0.0.0 0 if you had a /1 that turns 1 bit on in the subnet mask, so it would be 128.0.0.0.

If i had a /24 which is the subnet mask used for most small networks like your home router. There would be 255 minus 2 addresses available for clients (phones, pcs etc) so the subnet mask would have 24 on bits and read 255.255.255.0, which you may be familiar with.

(Assuming you dont know much, not to insult you, you might know plenty), but when writing any kind of instructions or guides, i was always told to assume the reader knows absolutely nothing and miss nothing out.

permalink
report
parent
reply
82 points
*

:00 - :ff

Edit: Just learnt this can be also noted as:

:: - ::f

permalink
report
reply
5 points

What about IPv4

permalink
report
parent
reply
68 points

0.0.0.0/0

permalink
report
reply
21 points

Better hope the goon hasn’t heard of IPv6 either, or you’re toast

permalink
report
parent
reply
22 points

::/0

permalink
report
parent
reply
0 points

Undefined

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

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

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 3.3K

    Monthly active users

  • 1K

    Posts

  • 37K

    Comments