-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfusioninventory-netdiscovery
executable file
·145 lines (109 loc) · 2.78 KB
/
fusioninventory-netdiscovery
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
#!/usr/bin/perl
use strict;
use warnings;
use English qw(-no_match_vars);
use Getopt::Long;
use Pod::Usage;
use FusionInventory::Agent::Task::NetDiscovery;
my $options = {
community => 'public'
};
GetOptions(
$options,
'first=s',
'last=s',
'dictionnary=s',
'community=s',
'help',
) or pod2usage(-verbose => 0);
pod2usage(-verbose => 0) if $options->{help};
die "no first address" unless $options->{first};
die "no last address" unless $options->{last};
my $discovery = FusionInventory::Agent::Task::NetDiscovery->new(
target => FusionInventory::Agent::Task::NetInventory::Target->new(
dictionnary => $options->{dictionnary}
)
);
$discovery->{options} = {
NAME => 'NETDISCOVERY',
PARAM => [
{
PID => 1,
THREADS_DISCOVERY => 1
}
],
RANGE => [
{
ID => 1,
IPSTART => $options->{first},
IPEND => $options->{last},
}
],
AUTHENTICATION => [
{
ID => 1,
COMMUNITY => $options->{community},
VERSION => 2
}
]
};
if ($options->{dictionnary}) {
die "no such file $options->{dictionnary}"
unless -f $options->{dictionnary};
$discovery->{options}->{DICO} = getDictionnary($options->{dictionnary});
}
$discovery->{client} =
FusionInventory::Agent::Task::NetInventory::Client->new();
$discovery->{deviceid} = 'foo';
$discovery->run();
sub getDictionnary {
my ($file) = @_;
open (my $handle, '<', $file) or die "Can't open $file: $ERRNO";
local $INPUT_RECORD_SEPARATOR;
my $string = <$handle>;
close $handle;
return $string;
}
package FusionInventory::Agent::Task::NetInventory::Client;
sub new {
my ($class) = @_;
return bless {}, $class;
}
sub send {
my ($self, %params) = @_;
print $params{message}->getContent();
}
package FusionInventory::Agent::Task::NetInventory::Target;
sub new {
my ($class, %params) = @_;
my $storage = FusionInventory::Agent::Task::NetInventory::Storage->new();
return bless {
storage => $storage
}, $class;
}
sub getStorage {
my ($self, %params) = @_;
return $self->{storage};
}
sub getUrl {
my ($self, %params) = @_;
return undef;
}
package FusionInventory::Agent::Task::NetInventory::Storage;
sub new {
my ($class) = @_;
return bless {}, $class;
}
sub save {
}
__END__
=head1 NAME
fusioninventory-discovery - Network inventory from command line
=head1 SYNOPSIS
fusioninventory-discovery [options] --start <start> --stop <stop>
Options:
-h --help this menu
--first start IP range first address
--last stop IP range last address
--dictionnary dictionnary file
--community community string (default: public)