我需要帮助修改此代码以扫描多个范围。它是perl,但我相信你可以帮我弄清楚如何让它开始和完成并扫描这两点之间的所有IP。这是代码:
#!C:\Program Files\perl\bin\Perl.exe -w
# ------------------------------------------------------------ #
use Net::Ping;
use LWP::UserAgent;
# ------------------------------------------------------------ #
# my $basenet = "192.168.240"; #
# my $start_host = 1; #
# my $end_host = 25; #
# ------------------------------------------------------------ #
$num_args = $#ARGV + 1;
if ($num_args != 3) {
print "Usage: perl.pl [network-base] [start_ip] [end_ip]\n\n";
print "Example: perl.pl 192.168.1 20 44\n";
print "This will run the check on these IP's: 192.168.1.20-44.\n";
exit -1;
}
my $basenet=$ARGV[0];
my $start_host=$ARGV[1];
my $end_host=$ARGV[2];
我猜它需要第四个参数。像
my $ extranet = $ ARGV [3];
请帮忙。
答案 0 :(得分:-2)
代码
use strict;
use warnings;
use Net::Ping;
use LWP::UserAgent;
my $num_args = $#ARGV + 1;
if ($num_args != 5) {
print "Usage: perl.pl [network-base] [start_ip] [end_ip] [range_start] [range_end]\n\n";
print "Example: perl.pl 192.168 20 30 1 2\n";
print "This will run the check on these IP's: 192.168.1.20- 192.168.2.30.\n";
exit -1;
}
my $basenet=$ARGV[0];
my $start_host=$ARGV[1];
my $end_host=$ARGV[2];
my $range_start =$ARGV[3];
my $range_end = $ARGV[4];
for(my $j =$range_start; $j<= $range_end ;$j++ )
{
for(my $i =$start_host; $i<= $end_host ;$i++)
{
my $new_ip = "$basenet.$j.$i";
print "$new_ip\n";
my $p = Net::Ping->new();
if ($p->ping($new_ip)) {
print "$new_ip : active\n";
}
else{
print "$new_ip : inactive\n";
}
}
}
以上代码将处理您的basenet,start_host和end_host数据,并根据这些输出生成IP,然后检查IP是否处于活动状态。
输出(使用:perl abc.pl 192.168 20 30 1 2
运行)
192.168.1.20 : inactive
192.168.1.21 : inactive
192.168.1.22 : inactive
192.168.1.23 : inactive
192.168.1.24 : inactive
192.168.1.25 : inactive
192.168.1.26 : inactive
192.168.1.27 : inactive
192.168.1.28 : inactive
192.168.1.29 : inactive
192.168.1.30 : inactive
192.168.2.20 : inactive
192.168.2.21 : inactive
192.168.2.22 : inactive
192.168.2.23 : inactive
192.168.2.24 : inactive
192.168.2.25 : inactive
192.168.2.26 : inactive
192.168.2.27 : inactive
192.168.2.28 : inactive
192.168.2.29 : inactive
192.168.2.30 : inactive
希望这会对你有所帮助