|
发表于 2010-2-20 11:09:55
|显示全部楼层
学习一下LWP,很强的东西
简单写一个whois,是用来通过IP地址来查询该IP上有多少域名
其实就是利用 whois.webhosting.info 站点返回页面进行罗列而已
当查询结果出现多个页面的时候,也做了处理,简单,很简单的东西:
#!/usr/bin/perl -w
# get the web site by ip address
use LWP::Simple;
my $arg = scalar @ARGV;
if ($arg != 1) {
print " Get the web site by ip address\n";
print " by python\@nsfocus.com\n";
print " Usage :\n";
print " perl $0 <IP>\n";
exit 0;
}
my $ip = $ARGV[0];
my $url = "http://whois.webhosting.info/$ip";
my $i = 1;
get_url($url);
sub get_url{
my $url = $_[0];
my @web = split /<\/td>/,get($url);
get_web_site(@web);
}
sub get_web_site{
my $w;
@web = @_;
foreach $w (@web) {
if ($w =~ /<td><a href=\"http:\/\/whois.webhosting.info\/(.*).\">.*<\/a>/) {
my $web = $1;
print $i,"\t=>\twwww.",$web,"\n";
$i++;
}
elsif ($w =~ /Next >><\/a>/){
print "Get the next page, Please wait ...\n";
the_next_page($w);
}
}
}
sub the_next_page{
my $shift = $_[0];
$shift =~ /pi=(\d)&ob=SLD&oo=ASC\">Next >><\/a>/;
my $n = $1;
my $url = "http://whois.webhosting.info/$ip?pi=$n&ob=SLD&oo=ASC";
get_url($url);
} |
|