#!/opt/local/bin/perl -w use strict; use Yahoo::Search; use vars qw( %nvdVendor $textName %foundName @Results ); open(VIN,"NVD-vendors.txt") or die "$0 : cant open support file NVD-vendors.txt\n"; while() { chomp; $nvdVendor{$_} = 1; } close(VIN); open(NIN,"NSRL-manufacturers.txt") or die "$0 : cant open support file NSRL-manufacturers.txt\n"; while() { chomp; $textName = $_; (defined $textName) or next; @Results = Yahoo::Search->Results(Doc => "$textName", AppId => "YahooDemo", Count => 6, Mode => 'all'); warn $@ if $@; # report any errors for my $Result (@Results) { addFullName($Result->Url); } print "$textName\t\t"; my %guesses; for my $k (keys %foundName) { if (defined $nvdVendor{$k}) { $guesses{"\{$k\}"} = 1; } else { if (closeEnuff($textName, $k)) { $guesses{"[$k]"} = 1; } else { $guesses{$k} = 1; } } delete $foundName{$k}; } print join("\t", (sort keys %guesses)); print "\n"; sleep(3); } # NIN exit; sub addFullName () { my $url = shift; $url = lc($url); ($url =~ /^http:/ ) or return(0); $url =~ s/http:\/\/// ; (my $n, my $p) = split(/\//,$url,2); # get the server name $n =~ s/^www\.// ; # strip common pre/postfixes $n =~ s/\.com$// ; $n =~ s/\.net$// ; $n =~ s/\.org$// ; $n =~ s/\.co\.uk$// ; $foundName{$n} += 1; return(1); } sub closeEnuff() { my $t = shift; my $y = shift; if ($t =~ / $y /i ) { return(1); } # does the candidate match a word in the text name? $t =~ s/ //g ; if ($t =~ /$y/i ) { return(1); } # does the candidate match the text name with spaces removed? # should do a check after removing special chars return(0); } __END__