ip address from range script
Karl Auer
kauer at biplane.com.au
Thu Jul 29 14:25:55 UTC 2010
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 at 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
More information about the ubuntu-users
mailing list