Php phát hiện ipv4 hoặc ipv6

Nếu bạn cần phát hiện xem một địa chỉ IP [giả sử 192. 168. 0. 2] nằm trong một dải IP/mạng con nhất định [giả sử 192. 168. 0. 0/24], bạn có thể sử dụng đoạn mã sau trong PHP

/**
 * Check IPv4 address is within a range
 *
 * @param string $ip A valid IPv4 address [xxx.xxx.xxx.xxx]
 * @param string $subnet A valid IPv4 subnet [xxx.xxx.xxx.xxx]
 * @param string $mask A valid IPv4 subnet mask [a number from 0-32]
 * @return boolean True if the address is within the range, false if it isn't
 */
function ip4_in_network[$ip, $subnet, $mask]
{
    if [$mask 

Chủ Đề