Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How to know wheter a certain IP address belongs to given network segments?
I have a network segment list in a text file called IPsegment.txt,it looks l
ike
this:

IPsegment.txt
219.111.192.0/18
68.132.0.0/17
67.146.0.0/16
192.162.0.0/16
152.172.0.0/16
34.132.0.0/14
97.208.0.0/13


And I have some IP addresses in another text file called IPlist.txt.It looks
like this:

IPlist.txt
www.yahoo.com,66.94.230.51
www.baidu.com,202.108.250.249
www.sina.com.cn,61.135.152.77
www.sohu.com,61.135.150.75
...

Now,I want to know whether the IP addresses in the IPlist.txt belongs the
network segment writen in the IPsegment.txt.
The mathing IP list is output in a new text file called matchinglist.txt.
It looks like this:

matchinglist.txt
www.baidu.com,202.108.250.249
www.sina.com.cn,61.135.152.77
...


How can I do that? Thank you in advance.

Report this thread to moderator Post Follow-up to this message
Old Post
Facco Eloelo
07-29-04 08:56 AM


Re: How to know wheter a certain IP address belongs to given network segments?
"Facco Eloelo" <artgh@hotmail.com> wrote in message
news:410c9fde.16854124@news.individual.net...
> I have a network segment list in a text file called IPsegment.txt,it looks
like
> this:
>
[snip]
>
> And I have some IP addresses in another text file called IPlist.txt.It
looks
> like this:
>
[snip]
>
> Now,I want to know whether the IP addresses in the IPlist.txt belongs the
> network segment writen in the IPsegment.txt.
> The mathing IP list is output in a new text file called matchinglist.txt.
> It looks like this:
>
[snip]
>
> How can I do that? Thank you in advance.

By splitting the fqdn and IPs into key/value pairs in a hash and then
checking the existence of the address against the hash. In the future,
please make an effort to solve your own problems before postng, and then if
you run into a specific problem you can always ask here.

Matt



Report this thread to moderator Post Follow-up to this message
Old Post
Matt Garrish
07-29-04 08:57 PM


Re: How to know wheter a certain IP address belongs to given network segments?
"Facco Eloelo" <artgh@hotmail.com> wrote in message
news:410c9fde.16854124@news.individual.net...
> I have a network segment list in a text file called IPsegment.txt,it looks
like
> this:
>
> IPsegment.txt
> 219.111.192.0/18
> 68.132.0.0/17
> 67.146.0.0/16
> 192.162.0.0/16
> 152.172.0.0/16
> 34.132.0.0/14
> 97.208.0.0/13
>
>
> And I have some IP addresses in another text file called IPlist.txt.It
looks
> like this:
>
> IPlist.txt
> www.yahoo.com,66.94.230.51
> www.baidu.com,202.108.250.249
> www.sina.com.cn,61.135.152.77
> www.sohu.com,61.135.150.75
> ...
>
> Now,I want to know whether the IP addresses in the IPlist.txt belongs the
> network segment writen in the IPsegment.txt.
> The mathing IP list is output in a new text file called matchinglist.txt.
> It looks like this:
>
> matchinglist.txt
> www.baidu.com,202.108.250.249
> www.sina.com.cn,61.135.152.77
> ...
>
>
> How can I do that? Thank you in advance.

This is not a Perl question.

That said, you can find several helpful tutorials with a Google search for
"ip addressing subnetting". Adding "Perl" to the search string shows at
least
one attempt at an IP address and subnet conversion calculator, done with
Perl.

One of the links that may be helpful to you is:

http://mipagina.cantv.net/lem/perl/iptut.htm

Search on the above page for "Matching against your address space" to see
how the module "NetAddr::IP" is used to solve a problem similar to (a part
of) your problem.

When you have a Perl problem, first read and comply with the Posting
Guidelines, then ask your Perl question.

Cheers.
--
Bill Segraves







Report this thread to moderator Post Follow-up to this message
Old Post
Bill Segraves
07-29-04 08:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 02:33 PM.

 

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.