Created
September 5, 2017 08:17
-
-
Save darkcolonist/8e8e9f45e0e8efb04ba2ab17c8dff2d1 to your computer and use it in GitHub Desktop.
check if ip-address is in-range
This file contains hidden or 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
<?php | |
$defaultIP = "122.3.33.186"; | |
$ip_start = "95.130.184.0"; | |
$ip_end = "95.130.191.254"; | |
$echo = array(); | |
$ip_start_long = ip2long($ip_start); | |
$ip_end_long = ip2long($ip_end); | |
$echo[] = $ip_start_long; | |
$echo[] = $ip_end_long; | |
$input = isset($_GET["ip"]) ? $_GET["ip"] : $defaultIP; | |
$inputLong = ip2long($input); | |
$in_range = false; | |
if(($ip_start_long <= $inputLong) && ($inputLong <= $ip_end_long)){ | |
$in_range = true; | |
} | |
$echo[] = $in_range ? "ip given is IN range" : "ip given is NOT IN range"; | |
echo "check between 95.130.184.0 and 95.130.191.254<br>"; | |
echo "your input: " . $input; | |
echo "<hr>"; | |
echo "<pre>"; | |
print_r($echo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment