You are here

public static function Helper::ip_mask_match in Anti Spam by CleanTalk 8.3

1 call to Helper::ip_mask_match()
Helper::ip_get in src/lib/Cleantalk/Common/Helper.php

File

src/lib/Cleantalk/Common/Helper.php, line 174

Class

Helper
Cleantalk's hepler class

Namespace

Drupal\cleantalk\lib\Cleantalk\Common

Code

public static function ip_mask_match($ip, $cidr) {
  if (is_array($cidr)) {
    foreach ($cidr as $curr_mask) {
      if (self::ip_mask_match($ip, $curr_mask)) {
        return true;
      }
    }
    unset($curr_mask);
    return false;
  }
  $exploded = explode('/', $cidr);
  $net = $exploded[0];
  $mask = 4294967295 << 32 - $exploded[1];
  return (ip2long($ip) & $mask) == (ip2long($net) & $mask);
}