Initial commit.

This commit is contained in:
2026-03-10 21:25:26 +08:00
commit 78739bf725
3089 changed files with 472990 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
<?php
// File name: ipv4addr.inc.php
// Description: PHP subroutine to handle the IPv4 addresses
// Date: 2007-01-30
// Author: imacat <imacat@pristine.com.tw>
// Copyright: Copyright (C) 2007 Pristine Communications
// ipv4_in_network: If an IP is in a network
function ipv4_in_network($network, $ip)
{
// Network in ddd.ddd.ddd.ddd/mm format
if (preg_match("/^(\d+)\.(\d+)\.(\d+)\.(\d+)\/(\d+)$/", $network, $m)) {
// Sanity check
settype($m[5], "integer");
if ($m[5] > 32) {
return null;
}
for ($i = 1; $i <= 4; $i++) {
settype($m[$i], "integer");
if ($m[$i] > 255) {
return null;
}
}
// Get the subnetwork mask
$masklen = $m[5];
for ($i = 0, $submask = 0; $i < $masklen; $i++) {
$submask |= 1 << (31 - $i);
}
$network = ip2long(sprintf("%d.%d.%d.%d", $m[1], $m[2], $m[3], $m[4]));
$network &= $submask;
// Malformed network
} else {
return null;
}
// IP in ddd.ddd.ddd.ddd format
if (preg_match("/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/", $ip, $m)) {
// Sanity check
for ($i = 1; $i <= 4; $i++) {
settype($m[$i], "integer");
if ($m[$i] > 255) {
return null;
}
}
$ip = ip2long(sprintf("%d.%d.%d.%d", $m[1], $m[2], $m[3], $m[4]));
// Malformed IP
} else {
return null;
}
return (($ip & $submask) == $network);
}
?>