Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Debian User (http://www.linux-archive.org/debian-user/)
-   -   ip address from range script (http://www.linux-archive.org/debian-user/405713-ip-address-range-script.html)

Jozsi Vadkan 07-29-2010 01:54 PM

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

Jozsi Vadkan 07-29-2010 01:54 PM

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:


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 1280411652.4287.28.camel@localhost">http://lists.debian.org/1280411652.4287.28.camel@localhost

Jozsi Vadkan 07-29-2010 01:54 PM

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:


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

Jozsi Vadkan 07-29-2010 01:54 PM

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:

--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

Marko Vojinovic 07-29-2010 02:23 PM

ip address from range script
 
On Thursday, July 29, 2010 14:54:15 Jozsi Vadkan wrote:
> 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?

One of the purposes of homework problems is to make you learn things by trying
to solve the problem *yourself*, rather than just studying a given solution.
The difference is in the amount of experience you gain by building your own
solution --- if you just try to understand someone else's solution, you can
reach some level of understanding, but miss out on this experience.

And precisely that experience is invaluable when you start facing problems
which nobody else has yet solved, later in your life.

HTH, :-)
Marko



--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

Karl Auer 07-29-2010 02:25 PM

ip address from range script
 
On Thu, 2010-07-29 at 15:54 +0200, Jozsi Vadkan wrote:
> 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

This is not a job for which a shell script is suited.

I would suggest python for this job, or any decent structured language
like C, C++, Java... perl as a last resort :-)

If you insist on using a shell script, look at the ipcalc program. It
will give you, for any network/mask, the minimum and maximum host
addresses in the network. If you normalised them so each octet was three
digits, and normalised the target IP address too, a simple comparison
would be possible. ipcalc normalises all addresses into binary, you
could use that directly instead of padding octets.

However, this is not going to be very fast, so hope that the number of
entries in at least one of your lists is very small... You could
preprocess the lists which would speed things up a bit.

Regards, K.

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer@biplane.com.au) +61-2-64957160 (h)
http://www.biplane.com.au/kauer/ +61-428-957160 (mob)

GPG fingerprint: B386 7819 B227 2961 8301 C5A9 2EBC 754B CD97 0156
Old fingerprint: 07F3 1DF9 9D45 8BCD 7DD5 00CE 4A44 6A03 F43A 7DEF


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

Todd Denniston 07-29-2010 02:40 PM

ip address from range script
 
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

--
Todd Denniston
Crane Division, Naval Surface Warfare Center (NSWC Crane)
Harnessing the Power of Technology for the Warfighter
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

Kwan Lowe 07-29-2010 04:17 PM

ip address from range script
 
On Thu, Jul 29, 2010 at 9:54 AM, Jozsi Vadkan <jozsi.avadkan@gmail.com> wrote:
> 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

Damn, how many places have you crossposted this?
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

Drew Weaver 07-29-2010 04:29 PM

ip address from range script
 
<?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!
";
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
";
} else {
echo " No Match
";
}
}
}
?>

-----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
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

John Doe 07-29-2010 04:31 PM

ip address from range script
 
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



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


All times are GMT. The time now is 05:13 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.