~bohwaz/blog/

Avec de vrais morceaux de 2.0 !

PHP IP utils update

PHP IP utils are now available in a new release.

This update brings a real normalize_ipv6 function which follows RFC 5952, as recommended by Stéphane Bortzmeyer. The previous behavior which expanded a short IPv6 address into a full long one is still available as expand_ipv6(), if needed.

I solved the problem of storing IPv6 addresses in mySQL (which doesn't support IPv6, a good reason to migrate to PostgreSQL) by using a VARBINARY field and inet_pton() function, you should do the same. It works for both IPv4 and IPv6 addresses. For SQLite, just use a BLOB field.

There is a new function available, check_ip, which checks wether an IP address matches against patterns given in an array. Patterns can be either IP addresses (eg 10.42.172.15), netmasks (eg 192.168.1.0/32, 2001::/16) or wildcards (eg 10.42.172.*, 2a01::*).

Still available at the same address : http://svn.kd2.org/svn/misc/libs/tools/ip_utils.php

Write a comment
(optional)
(optional)
(mandatory)
                           _   
  __ _ ___ ___  __ _ _   _| |_ 
 / _` / __/ __|/ _` | | | | __|
| (_| \__ \__ \ (_| | |_| | |_ 
 \__,_|___/___/\__,_|\__,_|\__|
                               
(mandatory)

URLs will create links automatically.
Allowed HTML tags: <blockquote> <cite> <pre> <code> <var> <strong> <em> <del> <ins> <kbd> <samp> <abbr>