From: Reedy Date: Tue, 11 Nov 2014 16:16:06 +0000 (+0000) Subject: Add IP::isInRanges() X-Git-Tag: 1.31.0-rc.0~13141 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=7b20bb4401653ad405ee66f2e19e7efb79229f1f;p=lhc%2Fweb%2Fwiklou.git Add IP::isInRanges() cf https://github.com/wikimedia/operations-mediawiki-config/blob/master/wmf-config/throttle.php#L43-L58 Change-Id: I8ae145035de9d349710971f17551da637e4d2242 --- 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.