This file is indexed.

/usr/bin/fusioninventory-netdiscovery is in fusioninventory-agent-task-network 1:2.3.16-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/perl

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

use strict;
use warnings;
use lib "/usr/share/fusioninventory/lib";

use English qw(-no_match_vars);
use Getopt::Long;
use Pod::Usage;

use FusionInventory::Agent::Task::NetDiscovery;
use FusionInventory::Agent::Logger;

my $options = {
    debug   => 0,
    threads => 1
};

my %setup = (
    confdir => "/etc/fusioninventory",
    datadir => "/usr/share/fusioninventory",
    libdir  => "/usr/share/fusioninventory/lib",
    vardir  => "/var/lib/fusioninventory-agent",
);

GetOptions(
    $options,
    'first=s',
    'last=s',
    'community=s@',
    'credential=s@',
    'entity=s',
    'threads=i',
    'timeout=i',
    'control',
    'debug+',
    'help',
    'version'
) or pod2usage(-verbose => 0);

if ($options->{version}) {
  print "NetDiscovery task $FusionInventory::Agent::Task::NetDiscovery::VERSION\n";
  exit 0;
}
pod2usage(-verbose => 0, -exitval => 0) if $options->{help};

pod2usage(
    -message => "no first address, aborting\n", -verbose => 0
) unless $options->{first};
pod2usage(
    -message => "no last address, aborting\n", -verbose => 0
) unless $options->{last};

my $verbosity =
    $options->{debug} == 0 ? LOG_INFO   :
    $options->{debug} == 1 ? LOG_DEBUG  :
    $options->{debug} == 2 ? LOG_DEBUG2 :
                             LOG_DEBUG2 ;

my $discovery = FusionInventory::Agent::Task::NetDiscovery->new(
    %setup,
    target => FusionInventory::Agent::Task::NetInventory::Target->new(),
    logger => FusionInventory::Agent::Logger->new(verbosity => $verbosity)
);

my $credentials_id = 1;
my @credentials;
if ($options->{community}) {
    foreach my $community (@{$options->{community}}) {
        push @credentials,
            { ID => $credentials_id++, VERSION => 1, COMMUNITY => $community };
    }
} elsif ($options->{credential}) {
    foreach my $specification (@{$options->{credential}}) {
        my $credential = { ID => $credentials_id++ };
        foreach my $parameter (split(',', $specification)) {
            my ($key, $value) = split(':', $parameter);
            $credential->{uc($key)} = $value;
        }
        push @credentials, $credential;
    }
} else {
    push @credentials, {
        ID => $credentials_id++, VERSION => 1, COMMUNITY => 'public'
    };
}

$discovery->{jobs} = [
    {
        params => {
            PID               => 1,
            THREADS_DISCOVERY => $options->{threads},
            TIMEOUT           => $options->{timeout},
        },
        ranges => [
            {
                ID      => 1,
                IPSTART => $options->{first},
                IPEND   => $options->{last},
            }
        ],
        credentials => \@credentials
    }
];
if (defined($options->{entity})) {
    $discovery->{options}->{RANGEIP}->[0]->{ENTITY} = $options->{entity};
}
$discovery->{client} =
    FusionInventory::Agent::Task::NetInventory::Client->new(
        control => $options->{control}
    );
$discovery->{deviceid} = 'foo';

$discovery->run();

package FusionInventory::Agent::Task::NetInventory::Client;

sub new {
    my ($class, %params) = @_;

    return bless {
        control => $params{control}
    }, $class;
}

sub send {
    my ($self, %params) = @_;

    # don't display control message by default
    return unless $self->{control}
        or $params{message}->{h}->{CONTENT}->{DEVICE};

    print $params{message}->getContent();
}

package FusionInventory::Agent::Task::NetInventory::Target;

sub new {
    my ($class, %params) = @_;

    return bless {}, $class;
}

sub getUrl {
    my ($self, %params) = @_;

    ## no critic (ExplicitReturnUndef)
    return undef;
}

__END__

=head1 NAME

fusioninventory-netdiscovery - Standalone network discovery

=head1 SYNOPSIS

fusioninventory-netdiscovery [options] --first <start> --last <stop>

  Options:
    --first address IP range first address
    --last address  IP range last address
    --credential    SNMP credential (default: version:1,community:public)
    --entity        GLPI entity
    --threads nb    number of discovery threads (default: 1)
    --timeout val   SNMP timeout (default: 1s)
    --control       output control messages
    --debug         debug output (execution traces)
    -h --help       print this message and exit
    --version       print the task version and exit

=head1 DESCRIPTION

F<fusioninventory-netdiscovery> allows to run a network discovery task without a
GLPI server.