From 7b20bb4401653ad405ee66f2e19e7efb79229f1f Mon Sep 17 00:00:00 2001 From: Reedy Date: Tue, 11 Nov 2014 16:16:06 +0000 Subject: [PATCH] Add IP::isInRanges() cf https://github.com/wikimedia/operations-mediawiki-config/blob/master/wmf-config/throttle.php#L43-L58 Change-Id: I8ae145035de9d349710971f17551da637e4d2242 --- includes/utils/IP.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/includes/utils/IP.php b/includes/utils/IP.php index 0e2db8cc07..77f9cd11fe 100644 --- a/includes/utils/IP.php +++ b/includes/utils/IP.php @@ -628,6 +628,25 @@ class IP { strcmp( $hexIP, $end ) <= 0 ); } + /** + * Determines if an IP address is a list of CIDR a.b.c.d/n ranges. + * + * @since 1.25 + * + * @param string $ip the IP to check + * @param array $ranges the IP ranges, each element a range + * + * @return bool true if the specified adress belongs to the specified range; otherwise, false. + */ + public static function isInRanges( $ip, $ranges ) { + foreach ( $ranges as $range ) { + if ( self::isInRange( $ip, $range ) ) { + return true; + } + } + return false; + } + /** * Convert some unusual representations of IPv4 addresses to their * canonical dotted quad representation. -- 2.20.1