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
|
package Ocsinventory::Agent::Backend::OS::HPUX::Networks;
sub check { can_load("Net::IP qw(:PROC)"); }
sub run {
my $params = shift;
my $common = $params->{common};
my $name;
my $lanid;
my $ipmask;
my $ipgateway;
my $status;
my $macaddr;
my $speed;
my $type;
my $ipsubnet;
my $description;
my $ipaddress;
my $binip;
my $binmask;
my $binsubnet;
for ( `lanscan -iap`) {
# Reinit variable
$name="";
$lanid="";
$ipmask="";
$ipgateway="";
$status="";
$macaddr="";
$speed="";
$type="";
$ipsubnet="";
$description="";
$ipaddress="";
if ( /^(\S+)\s(\S+)\s(\S+)\s+(\S+)/) {
$name=$2;
$macaddr=$1;
$lanid=$4;
#print "name $name macaddr $macaddr lanid $lanid\n";
for ( `lanadmin -g $lanid` ) {
if (/Type.+=\s(.+)/) { $type = $1; };
if (/Description\s+=\s(.+)/) { $description = $1; };
if (/Speed.+=\s(\d+)/) {
$speed = $1;
unless ( $speed <= 1000000 ) { # in old version speed was given in Mbps
# we want speed in Mbps
$speed = $1/1000000;
}
};
if (/Operation Status.+=\s(.+)/) { $status = $1; };
}; # for lanadmin
#print "name $name macaddr $macaddr lanid $lanid speed $speed status $status \n";
for ( `ifconfig $name 2> /dev/null` ) {
if ( /inet\s(\S+)\snetmask\s(\S+)\s/ ) {
$ipaddress=$1;
$ipmask=$2;
if ($ipmask =~ /(..)(..)(..)(..)/) {
$ipmask=sprintf ("%i.%i.%i.%i",hex($1),hex($2),hex($3),hex($4));
}
};
}; # For ifconfig
$binip = ip_iptobin ($ipaddress ,4);
$binmask = ip_iptobin ($ipmask ,4);
$binsubnet = $binip & $binmask;
$ipsubnet = ip_bintoip($binsubnet,4);
$common->addNetworks({
DESCRIPTION => $description,
IPADDRESS => $ipaddress,
IPGATEWAY => $ipgateway,
IPMASK => $ipmask,
IPSUBNET => $ipsubnet,
MACADDR => $macaddr,
STATUS => $status,
SPEED => $speed,
TYPE => $type,
});
}; # If
}; # For lanscan
}
1;
|