[CentOS] ip address from range script

Thu Jul 29 16:29:25 UTC 2010
Drew Weaver <drew.weaver at thenap.com>

$ranges = array(
          array(ip2long(''), ip2long('')),
          array(ip2long(''), ip2long('')));
$ips = array("", "");

function checkip($ip, $range) {
        $ip = (integer) ip2long($ip);
        if(($ip >= $range[0]) and ($ip <= $range[1])) {
                return true;
foreach ($ips as $ip) {
        echo "Checking $ip!\n";
        foreach ($ranges as $range) {
                $rd_displaya = long2ip($range[0]);
                $rd_displayb = long2ip($range[1]);
                echo "Checking for $ip in $rd_displaya - $rd_displayb";
                if (checkip($ip, $range) === TRUE) {
                        echo " Match\n";
                } else {
                        echo " No Match\n";

-----Original Message-----
From: centos-bounces at centos.org [mailto:centos-bounces at centos.org] On Behalf Of Jozsi Vadkan
Sent: Thursday, July 29, 2010 9:54 AM
To: Centos Mailing List
Subject: [CentOS] ip address from range script

TEST-A.txt: list of ip address ranges [AS/isp's in a country]
TEST-B.txt: list of ip addresses

I just need to know, if an ip in the TEST-B.txt is in a range of

cat "TEST-A.txt";9007;44536;9000;8263;9001;6852

cat "TEST-B.txt"


-> so is an ip address [in TEST-B.txt] is from my country [TEST-A.txt]
or not?


CentOS mailing list
CentOS at centos.org