PROJET AUTOBLOG


BohwaZ

Archivé

Site original : BohwaZ

⇐ retour index

PHP IP utils update

mardi 27 mars 2012 à 01:24

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