#!/usr/bin/perl
use LWP::Simple;
use warnings;
$content = 0;
$find = "webvis.edgesuite.net";
open (HOSTLIST,"lists.hosts");
@hosts = <HOSTLIST>;
foreach $host(@hosts) {
$results = `nslookup www.$host`;
my $pos = index($results, $find);
if ($pos > -1 )
{
my $url = "http://www.$host";
$content = get ($url);
print $content;
my $pos1 = index($content, $url);
if($pos1 > -1) {
print "Content Match\n";
} else {
print "No Content Match\n";
}
$count++;
chomp ($host);
print "$count www.$host\n";
}
}
close (HOSTLIST);
exit($errorcode);
使用上面的代码,我总是收到以下错误:
IO::Socket::INET: 错误的主机名 'www.test.com
如果将 $url 更改为:
$url = 'http://www.test.com';
我从页面获取内容检索。
所以我的问题是如何将字符串变量传递给 get 属性,这样它就不会产生错误的主机名错误?
先感谢您