-
-
Save stklcode/59447dd8419ad79d2bcd5d38d733ea65 to your computer and use it in GitHub Desktop.
Modified ip_in_range() method for the "Limit Login Attempts Reloaded" WP plugin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function ip_in_range( $ip, $list ) { | |
$bytes_ip = inet_pton( $ip ); | |
foreach ( $list as $range ) { | |
$range = array_map( 'trim', explode( '-', $range ) ); | |
if ( count( $range ) == 1 ) { | |
$bytes_range = inet_pton( $range[0] ); | |
if ( $bytes_ip === $bytes_range ) { | |
return true; | |
} | |
} else { | |
$low = inet_pton( $range[0] ); | |
$high = inet_pton( $range[1] ); | |
if ( $low === false || $high === false || $bytes_ip === false ) { | |
continue; | |
} | |
$low = bin2hex( inet_pton( $low ) ); | |
$high = bin2hex( inet_pton( $high ) ); | |
$needle = bin2hex( $bytes_ip ); | |
if ( $needle >= $low && $needle <= $high ) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment