• FauxPseudo
    link
    fedilink
    2938 months ago

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

    • Danny M
      link
      fedilink
      76
      edit-2
      8 months ago

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

        • Danny M
          link
          fedilink
          3
          edit-2
          8 months ago

          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)
          
      • Centillionaire
        link
        fedilink
        698 months ago

        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
          link
          fedilink
          138 months ago

          So add two more octets:

          Moat companies will still just use something like 10.0.13.37.0.1

          • @0xD
            link
            118 months ago

            IPv6 is not made with internal networks in mind lol

            • @dan@upvote.au
              link
              fedilink
              18 months 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.

              • @dohpaz42@lemmy.world
                cake
                link
                fedilink
                English
                178 months ago

                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
                  link
                  fedilink
                  -28 months ago

                  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.

        • alienzx
          link
          fedilink
          English
          4
          edit-2
          8 months 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
        link
        fedilink
        158 months ago

        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

    • @Mr_Dr_Oink@lemmy.world
      link
      fedilink
      68 months ago

      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

      • @Static_Rocket@lemmy.world
        link
        fedilink
        English
        18 months ago

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

      • @Mr_Dr_Oink@lemmy.world
        link
        fedilink
        18 months ago

        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.

  • agilob
    link
    fedilink
    English
    78
    edit-2
    8 months ago

    :00 - :ff

    Edit: Just learnt this can be also noted as:

    :: - ::f

  • @dan@upvote.au
    link
    fedilink
    25
    edit-2
    8 months ago

    This reminds me of something I saw online maybe 20 years ago now. Someone created a torrent with a name like “every IP address ever (hacking tool)” and uploaded it to Suprnova, which ended up having thousands of people seeding it. It was just a text file with every IPv4 from 0.0.0.0 to 255.255.255.255 😂

      • @spuncertv@iusearchlinux.fyi
        link
        fedilink
        9
        edit-2
        8 months ago

        That file would be ungodly large. There are 2^128 possible addresses, each weighing in at 128 bits, 16 bytes. 16 bytes times 340 trillion trillion trillion. That puts us around 5.44 trillion Zettabytes. The estimates I’ve seen for worldwide data storage sit aroun 60-70 zettabytes.

      • @dan@upvote.au
        link
        fedilink
        5
        edit-2
        8 months ago

        IPv6 version is just a Python script that generates random 128-bit integers. Eventually you’ll hit a valid IPv6 address!

  • @doctorcrimson@lemmy.today
    link
    fedilink
    23
    edit-2
    8 months ago

    ipv4 [0,255].[0,255].[0,255].[0,255]

    ipv6 [0000,ffff]:[0000,ffff]:[0000,ffff]:[0000,ffff]:[0000,ffff]:[0000,ffff]:[0000,ffff]:[0000,ffff]