27 lines
611 B
PHP
27 lines
611 B
PHP
<?php
|
|
|
|
$allowedSubnets = [
|
|
'192.168.1.0/24',
|
|
'10.0.0.0/8',
|
|
'172.16.0.0/12',
|
|
'77.91.72.48/32',
|
|
'93.140.0.0/12',
|
|
'94.140.0.0/12'
|
|
];
|
|
|
|
function isAllowedIP($ip, $subnets) {
|
|
foreach ($subnets as $subnet) {
|
|
list($subnetBase, $bits) = explode('/', $subnet);
|
|
$ipLong = ip2long($ip);
|
|
$subnetLong = ip2long($subnetBase);
|
|
$mask = -1 << (32 - $bits);
|
|
$subnetLong &= $mask;
|
|
|
|
if (($ipLong & $mask) === $subnetLong) {
|
|
return true; // Совпадение найдено
|
|
}
|
|
}
|
|
return false; // Нет совпадений
|
|
}
|
|
|