Regular Expression for IPv6 addresses

Jeroen Massar jeroen at unfix.org
Thu Feb 4 18:31:59 CST 2010


Richard E. Brown wrote:
> Folks,
> 
> My company, Dartware, have derived a regex for testing whether an IPv6
> address is correct. I've posted it in my blog:
> 
>     http://intermapper.ning.com/profiles/blogs/a-regular-expression-for-ipv6
> 
> 
> This has links to the regular expression, a (Perl) program that tests
> various correct and malformed addresses, and a Ruby implementation of
> the same.

You know, link local addresses (fe80::/10) are quite useless without
specifying the zone of that address. See section 11 of RFC4007.

The only proper way of "testing" if an address is a valid IPv6 address
is to feed it to getaddrinfo() and then use it through that API.
Yes, you can make some assumptions, but it has shown that people
assuming that everything stayed under 2001::/16 also got it wrong at one
point in time. Thus just feed it to getaddrinfo() if you really need it.

Greets,
 Jeroen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: OpenPGP digital signature
URL: <http://mailman.nanog.org/pipermail/nanog/attachments/20100204/15b3f89f/attachment.bin>


More information about the NANOG mailing list