diff options
author | Christian Pointner <equinox@ffgraz.net> | 2008-12-06 07:23:29 +0000 |
---|---|---|
committer | Christian Pointner <equinox@ffgraz.net> | 2008-12-06 07:23:29 +0000 |
commit | 61448e4c2aabaf06cdae4160de77aaac8c7ad692 (patch) | |
tree | 52cf75f52eb999b9677af33c42556d1deec41372 /ipmatch.php | |
parent | 9cee05c341490e0329311a16c0d54a8c27ec5143 (diff) |
added data.php
Diffstat (limited to 'ipmatch.php')
-rw-r--r-- | ipmatch.php | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/ipmatch.php b/ipmatch.php new file mode 100644 index 0000000..058f878 --- /dev/null +++ b/ipmatch.php @@ -0,0 +1,17 @@ +<?php +function match_network ($nets, $ip) { + foreach ($nets as $net) { + $ip_arr = explode('/', $net); + if (!$ip_arr[1]) + $ip_arr[1] = '32'; + + $net_long = ip2long($ip_arr[0]); + $x = ip2long($ip_arr[1]); + $mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]); + $ip_long = ip2long($ip); + + if (($ip_long & $mask) == ($net_long & $mask)) return true; + } + return false; +} +?> |