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:\
Jozsi Vadkan wrote, On 07/29/2010 09:54 AM:
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
cat "TEST-B.txt" 63.31.63.2
-> so is an ip address [in TEST-B.txt] is from my country [TEST-A.txt] or not?
thanks:\
perhaps the tools linked to from the following list message(s) will be of use in creating the tool you want. http://lists.centos.org/pipermail/centos/2009-December/087863.html and (If I read correctly) it is available in EPEL http://lists.centos.org/pipermail/centos/2009-December/087866.html
<?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@centos.org [mailto:centos-bounces@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 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@centos.org http://lists.centos.org/mailman/listinfo/centos
From: Jozsi Vadkan jozsi.avadkan@gmail.com
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?
I have to go home soon, so here's a quick and dirty shell script that should work (uses ipcalc):
#!/bin/bash cat TEST-A.txt | while read LINE do RANGE=`echo $LINE | cut -d';' -f1` echo `ipcalc -n $RANGE | grep "^HostM" | awk ' { print $2 } ' | awk -F. -v r=$LINE ' { print r" "$1*16777216+$2*65536+$3*256+$4; } '` | while read INTRANGE do set $INTRANGE echo $1 cat TEST-B.txt | while read ANIP do INTIP=`echo $ANIP | awk -F. ' { print $1*16777216+$2*65536+$3*256+$4; } '` if [ $INTIP -ge $2 -a $INTIP -le $4 ]; then echo " "$ANIP fi done done done
=>
63.31.63.0/24;9007;44536 63.31.63.2 63.31.63.66 64.65.0.0/19;9000;8263 62.64.14.0/21;9001;6852 62.64.14.231
JD