Skip to content

Commit

Permalink
Merge pull request #485 from OCSInventory-NG/useFpingSnmp
Browse files Browse the repository at this point in the history
refactor(SnmpScan): use fping for snmp subnet scanning
  • Loading branch information
fbomj authored Oct 15, 2024
2 parents ad2e2b5 + 9c6da94 commit 9266ddb
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions lib/Ocsinventory/Agent/Modules/SnmpScan.pm
Original file line number Diff line number Diff line change
Expand Up @@ -439,23 +439,18 @@ sub snmp_ip_scan {
my $snmp_scan_type = $self->{scan_type_snmp};

# check for scan type and if the required module is available
if ($snmp_scan_type eq 'ICMP' && $common->can_load('Net::Ping')) {
my $block=Net::Netmask->new($net_to_scan);
my $size=$block->size()-2;
my $index=1;
$logger->debug("Scanning $net_to_scan with ping");
my $ping=Net::Ping->new("icmp",1);

while ($index <= $size) {
my $res=$block->nth($index);
if ($ping->ping($res)) {
$logger->debug("Found $res");
push( @{$self->{netdevices}},{ IPADDR=>$res }) unless $self->search_netdevice($res);
}
if ($snmp_scan_type eq 'ICMP' && $common->can_run('fping')) {
my $block = Net::Netmask->new($net_to_scan);
my $network = $block->base() . "/" . $block->bits();
$logger->debug("Scanning $network with fping");

my $fping_output = `fping -aq -g $network 2>/dev/null`;
my $index = 1;
foreach my $ip (split /\n/, $fping_output) {
$logger->debug("Found $ip");
push(@{$self->{netdevices}}, { IPADDR => $ip }) unless $self->search_netdevice($ip);
$index++;
}
$ping->close();

} elsif ($snmp_scan_type eq 'NMAP' && $common->can_load('Nmap::Parser')) {
$logger->debug("Scanning $net_to_scan with nmap");
my $nmaparser = Nmap::Parser->new;
Expand Down

0 comments on commit 9266ddb

Please sign in to comment.