【发布时间】:2010-05-03 23:31:23
【问题描述】:
我有判断一个IP是否进入特定IP范围的PHP函数,但我不知道如何找出IP的网络和掩码。有人可以帮忙吗?
<?
// Example of calling and checking IP-address 192.168.0.4
// belonging to a network 192.168.0.0 with mask 255.255.255.248
if(ip_vs_net("192.168.0.4","192.168.0.0","255.255.255.248")){
print "Address belongs to a netwok<BR>";
} else {
print "Address is out of subnetwork's range<BR>";
}
function ip_vs_net($ip,$network,$mask){
if(((ip2long($ip))&(ip2long($mask)))==ip2long($network)){
return 1;
} else {
return 0;
}
}
?>
【问题讨论】:
-
我需要在我的网站上创建安全措施,允许每位用户仅使用 1 个 IP 子网。用户的 IP 将是使用拨号互联网连接的动态“原因”,但将在一个 IP 子网内。我想限制使用不同的 IP 子网,但只有一个将在第一次访问用户区域时确定并存储在白名单中以供确定的用户使用。