// Some regex definition to "play" with IP address and IP address blocks
// An IP is made of 4 bytes from x00 to xFF which is d0 to d255
-define( 'RE_IP_BYTE', '(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)');
+define( 'RE_IP_BYTE', '(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|0?[0-9]?[0-9])');
define( 'RE_IP_ADD' , RE_IP_BYTE . '\.' . RE_IP_BYTE . '\.' . RE_IP_BYTE . '\.' . RE_IP_BYTE );
// An IP block is an IP address and a prefix (d1 to d32)
define( 'RE_IP_PREFIX', '(3[0-2]|[12]?\d)');
/**
* Split out an IP block as an array of 4 bytes and a mask,
- * return false if it cant be determined
+ * return false if it can't be determined
*
* @parameter $ip string A quad dotted IP address
* @return array
$unsignedIP = IP::toUnsigned($addr);
list( $start, $end ) = IP::parseRange($range);
- $start = hexdec($start);
- $end = hexdec($end);
+ $start = hexdec($start);
+ $end = hexdec($end);
return (($unsignedIP >= $start) && ($unsignedIP <= $end));
}
require 'Test.php';
-plan( 'no_plan' );
+plan( 1120 );
require_ok( 'includes/IP.php' );
}
}
-$valid = array( '216.17.184.1', '0.0.0.0', '000.000.000.000' );
-
-foreach ( $valid as $v ) {
- ok( IP::isValid( $v ), "$v is a valid IPv4 address" );
+# A bit excessive perhaps? meh..
+foreach ( range( 256, 999 ) as $i ) {
+ $a = sprintf( "%03d", $i );
+ $b = sprintf( "%02d", $i );
+ $c = sprintf( "%01d", $i );
+ foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
+ $ip = "$f.$f.$f.$f";
+ ok( ! IP::isValid( $ip ), "$ip is not a valid IPv4 address" );
+ }
}
$invalid = array(
ok( ! IP::isPublic( $p ), "$p is not a public IP address" );
}
-#is ('127.0.0.1', is_loopback_ipv4('127.0.0.1'), 'is_loopback_ipv4 127.0.0.1');
-#is ('192.0.2.9', is_testnet_ipv4('192.0.2.9'), 'is_testnet_ipv4 192.0.2.9');
-#is ('216.17.184.1', is_public_ipv4('216.17.184.1'), 'is_public_ipv4 216.17.184.1');
-#isnt ('192.168.0.1', is_public_ipv4('192.168.0.1'), 'is_public_ipv4 192.168.0.1');
-#
-?>
\ No newline at end of file
+?>