Re: ip address from range script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



<?php
$ranges = array(
          array(ip2long('63.31.63.0'), ip2long('63.31.63.255')),
          array(ip2long('64.65.0.0'), ip2long('64.65.31.255')));
$ips = array("63.31.63.2", "64.66.5.4");

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@xxxxxxxxxx [mailto:centos-bounces@xxxxxxxxxx] On Behalf Of Jozsi Vadkan
Sent: Thursday, July 29, 2010 9:54 AM
To: Centos Mailing List
Subject:  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
TEST-A.txt

cat "TEST-A.txt"
63.31.63.0/24;9007;44536
64.65.0.0/19;9000;8263
62.64.14.0/21;9001;6852

cat "TEST-B.txt"
63.31.63.2
64.66.5.4
63.31.63.66
62.64.14.231

output: 
63.31.63.0/24;9007;44536
	63.31.63.2
	63.31.63.66
62.64.14.0/21;9001;6852
	62.64.14.231


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

thanks:\

_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos


[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux