From a8c527a8b00a11988fd738def0d689836853bff0 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 20 Feb 2008 09:53:06 +0000 Subject: [PATCH] Added new test. -Test if a given IP Address is within a specific range. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8980 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/utils/class_tests.inc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gosa-core/include/utils/class_tests.inc b/gosa-core/include/utils/class_tests.inc index ba28e0550..4fa85ce41 100644 --- a/gosa-core/include/utils/class_tests.inc +++ b/gosa-core/include/utils/class_tests.inc @@ -232,6 +232,22 @@ class tests { return ($first < $curr&& $last > $curr); } + + + /* Check if the specified IP address $address is inside the given network */ + public static function is_in_ip_range($from, $to, $address) + { + $from = split('\.', $from); + $to = split('\.', $to); + $ad = split('\.', $address); + + /* Transform to integer */ + $from= $from[0] * (16777216) + $from[1] * (65536) + $from[2] * (256) + $from[3]; + $to= $to[0] * (16777216) + $to[1] * (65536) + $to[2] * (256) + $to[3]; + $ad= $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3]; + + return ($ad >= $from && $ad <= $to); + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -- 2.30.2