繁体   English   中英

使用ip从ip范围中找到免费的ip地址

[英]find free ip address from ip range with php

我有2张桌子

table1 ip_pool-从10.0.0.2到10.0.0.254

table2用户-用户1 ip地址10.0.0.2,用户2 ip地址10.0.0.3

如何找到下一个免费IP示例10.0.0.4

尝试过此代码,但它向我显示了所有IP

function ip_range($start, $end)
{
$start = ip2long($start);
$end = ip2long($end); 
return array_map('long2ip', range($start, $end) );
}

$range_one = "10.0.0.2";
$range_two = "10.0.0.254";
print_r( ip_range($range_one, $range_two) );

我认为此SQL可以满足您的要求:

select p.*
from ip_pool p
where p.ip_address not in (select u.ip_address from users u)
order by p.id_address
limit 1;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM