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 outputed into 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
....
This is what I code:
It doesn't work. :-(
can anyone help me fix it?I'm a perl newbie.thanks.
#!/usr/bin/perl
my %ip;
open FH,'<','d:\a\IPSegment.txt';
while (<FH>) {
chomp($_);
$ip{$_}=0;
}
close FH;
open FH,'<','d:\a\IPList.txt';
open FH2,'>>','d:\a\Matchlist.txt';
while (<FH>) {
chomp ($_);
$rec=$_;
($domain, $domip) = split(/,/, $_);
if ($ip{'$domip'} > 0) {
print FH2 $rec,"\n";
$ip{'$domip'}++; #increment a counter here, output from hash
}
}
close FH;
close FH2;
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 outputed into 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
....
This is what I code:
It doesn't work. :-(
can anyone help me fix it?I'm a perl newbie.thanks.
#!/usr/bin/perl
my %ip;
open FH,'<','d:\a\IPSegment.txt';
while (<FH>) {
chomp($_);
$ip{$_}=0;
}
close FH;
open FH,'<','d:\a\IPList.txt';
open FH2,'>>','d:\a\Matchlist.txt';
while (<FH>) {
chomp ($_);
$rec=$_;
($domain, $domip) = split(/,/, $_);
if ($ip{'$domip'} > 0) {
print FH2 $rec,"\n";
$ip{'$domip'}++; #increment a counter here, output from hash
}
}
close FH;
close FH2;