이것은 내가 생각해 낸 작은 것입니다. 확인해야 할 다른 방법이있을 것이라고 확신하지만, 이는 내 목적을 위해 할 것입니다.
예를 들어 IP 주소 10.0.0.1이 10.0.0.1과 10.1.0.0 사이에 있는지 알고 싶으면 다음 명령을 실행합니다.
var_dump(ip_in_range("10.0.0.1", "10.1.0.0", "10.0.0.1"));
그리고이 경우 IP 주소가 범위 내에 있음을 확인하는 true를 반환합니다.
# We need to be able to check if an ip_address in a particular range
function ip_in_range($lower_range_ip_address, $upper_range_ip_address, $needle_ip_address)
{
# Get the numeric reprisentation of the IP Address with IP2long
$min = ip2long($lower_range_ip_address);
$max = ip2long($upper_range_ip_address);
$needle = ip2long($needle_ip_address);
# Then it's as simple as checking whether the needle falls between the lower and upper ranges
return (($needle >= $min) AND ($needle <= $max));
}
주소 범위는 어떻게 지정합니까? – Anigel
이 질문에 대한 자세한 내용은 좋은 Q & A가되도록 –
IP의 서브넷 범위를 얻으려고하거나 감지 된 주소가 지정된 배열 내에 있는지 확인 하시겠습니까? –