- $matches = array();
- foreach ($no_proxy as $network) {
- if ($is_valid && preg_match(PKWK_CIDR_NETWORK_REGEX, $network, $matches)) {
- // Sample: '10.0.0.0/8' or '10.0.0.0/255.0.0.0'
- $l_net = ip2long($matches[1]); // '10.0.0.0'
- $mask = isset($matches[2]) ? $matches[2] : 32; // '8' or '255.0.0.0'
- $mask = is_numeric($mask) ?
- pow(2, 32) - pow(2, 32 - $mask) : // '8' means '8-bit mask'
- ip2long($mask); // '255.0.0.0' (the same)
-
- if (($l_ip & $mask) == $l_net) return FALSE;
- } else {
- // Hostname, or a part of hostname
- if (preg_match('/' . preg_quote($network, '/') . '$/', $host))
- return FALSE;
+ if (is_long($l_ip) && long2ip($l_ip) == $ip) {
+ // $host seems valid IPv4 address
+ foreach ($networks as $network) {
+ if (preg_match(PKWK_CIDR_NETWORK_REGEX, $network, $matches)) {
+ // Sample: '10.0.0.0/8' or '10.0.0.0/255.0.0.0'
+ $l_net = ip2long($matches[1]); // '10.0.0.0'
+ $mask = isset($matches[2]) ? $matches[2] : 32; // '8' or '255.0.0.0'
+ $mask = is_numeric($mask) ?
+ pow(2, 32) - pow(2, 32 - $mask) : // '8' means '8-bit mask'
+ ip2long($mask); // '255.0.0.0' (the same)
+
+ if (($l_ip & $mask) == $l_net) return TRUE;
+ }