You are here

function fail2ban_ip_in_network in Fail2ban Firewall Integration 6

Same name and namespace in other branches
  1. 7 fail2ban.module \fail2ban_ip_in_network()

Check if a given address exists on a network.

Shamelessly copied from http://php.net/manual/en/function.ip2long.php

1 call to fail2ban_ip_in_network()
fail2ban_whitelist in ./fail2ban.module
Check if a given address is whitelisted.

File

./fail2ban.module, line 179

Code

function fail2ban_ip_in_network($ip, $net_addr, $net_mask) {
  if ($net_mask <= 0) {
    return FALSE;
  }
  $ip_binary_string = sprintf("%032b", ip2long($ip));
  $net_binary_string = sprintf("%032b", ip2long($net_addr));
  return substr_compare($ip_binary_string, $net_binary_string, 0, $net_mask) === 0;
}