How to know wheter a certain IP address belongs to given network segments?

F

Facco Eloelo

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.
 
M

Matt Garrish

Facco Eloelo said:
I have a network segment list in a text file called IPsegment.txt,it looks like
[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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top