IPv6 addresses

Chris Dennis cgdennis at btinternet.com
Mon Mar 12 13:38:50 GMT 2012


On 12/03/12 07:20, Paul Makepeace wrote:
> On Sun, Mar 11, 2012 at 15:43, Chris Dennis<cgdennis at btinternet.com>  wrote:
>> Hello folks
>>
>> I'm hacking together a quick script to parse the output from the 'ip'
>> command on Linux, e.g.
>>
>> $ ip a s
>> 1: lo:<LOOPBACK,UP,LOWER_UP>  mtu 16436 qdisc noqueue state UNKNOWN
>> � �link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
>> � �inet 127.0.0.1/8 scope host lo
>> � �inet6 ::1/128 scope host
>> � � � valid_lft forever preferred_lft forever
>> 2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP>  mtu 1500 qdisc mq state UP qlen
>> 1000
>> � �link/ether 00:19:b9:06:4c:86 brd ff:ff:ff:ff:ff:ff
>> � �inet 192.168.1.7/24 brd 192.168.1.255 scope global eth0
>> � �inet6 2001:dead:beef:cafe::1/64 scope global dynamic
>> � � � valid_lft 86147sec preferred_lft 14147sec
>> � �inet6 fe80::1/64 scope link
>> � � � valid_lft forever preferred_lft forever
>>
>> -- which is straightforward. �But then I need to process the IPv6 addresses
>> to be able to extract subnet prefixes etc.
>
> $ /sbin/ifconfig  | perl -MRegexp::IPv6=\$IPv6_re -lne
> '/(?:($IPv6_re)(\/\d+))/ and print "net $1 size $2"'
> net fe80::fcff:ff:fe00:5272 size /64
> net ::1 size /128

Thanks for your reply.

I obviously worded my question very badly.  By 'process the IPv6 
addresses' I meant 'convert e.g. 2001:dead:beef:cafe::1 into some sort 
of bit string and then apply a 64-bit mask to give 
2001:dead:beef:cafe::'.  That isn't always as trivial as it seems in 
that example.

Modules such as NetAddr::IP::Util provide functions for that sort of thing.

I was just asking for recommendations as to which of the many available 
modules are well regarded.

cheers

Chris
-- 
Chris Dennis                                  cgdennis at btinternet.com
Fordingbridge, Hampshire, UK


More information about the london.pm mailing list