Merged in feature/280-dev-dev01 (pull request #21)
auto-patch 280-dev-dev01-2024-01-19T16_41_58 * auto-patch 280-dev-dev01-2024-01-19T16_41_58
This commit is contained in:
16
wp/wp-content/plugins/ip-geo-block/includes/Net/IPv4.php
Normal file
16
wp/wp-content/plugins/ip-geo-block/includes/Net/IPv4.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Class to provide IPv4 calculations
|
||||
*
|
||||
* PHP versions 4, 5 and 7
|
||||
*
|
||||
* @link https://stackoverflow.com/questions/594112/matching-an-ip-to-a-cidr-mask-in-php-5#answer-594134
|
||||
*/
|
||||
|
||||
class Net_IPv4 {
|
||||
public static function ipInNetwork( $ip, $cidr ) {
|
||||
list( $subnet, $bitmask ) = explode( '/', $cidr );
|
||||
$bitmask = -1 << ( 32 - $bitmask );
|
||||
return ( ip2long( $ip ) & $bitmask ) === ( ip2long( $subnet ) & $bitmask );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user