Umdurman has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I would like to extract the IPv4 from an IPv6 with use Net::IP in Perl. IPv6 = 2a02:a420:3a:d2b2:84b7:7df7:10ff:218d Could you please show me an example? Kind regards,

Replies are listed 'Best First'.
Re: Net::IP example
by 1nickt (Canon) on Nov 29, 2023 at 23:18 UTC
Re: Net::IP example
by cavac (Prior) on Dec 01, 2023 at 13:17 UTC

    This only works in cases where the IPv4 address is really encoded in the IPv6 one at a known location. IPv6 addresses might not encode ANY IPv4, any even if they do, they don't always have to follow a specific scheme. For example, on my old server, the last 5 numbers, decoded to decimal, where in the form of:

    10 0 0 138 2

    Where the last digit was the number of the virtual machine or service i wanted to have their own IPv6. Basically, i shifted the whole IPv4 one byte to the left, so i could have sub-numbering of stuff running on that IPv4 address.

    PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP