source: ocsinventory-agent/trunk/fuentes/lib/Ocsinventory/Agent/Backend/OS/Solaris/IPv4.pm @ 468

Last change on this file since 468 was 468, checked in by mabarracus, 4 years ago

Copyt trusty code

File size: 987 bytes
Line 
1package Ocsinventory::Agent::Backend::OS::Solaris::IPv4;
2
3sub check { can_run ("ifconfig") }
4
5# Initialise the distro entry
6sub run {
7  my $params = shift;
8  my $common = $params->{common};
9  my %ip;
10  my $ip;
11  my $hostn;
12
13#Looking for ip addresses with ifconfig, except loopback
14# Solaris need -a option
15  for(`ifconfig -a`){#ifconfig in the path
16#Solarisligne inet
17    if(/^\s*inet\s+(\S+).*/){($1=~/127.+/)?next:($ip{$1}=1)};
18  }
19
20# Ok. Now, we have the list of IP addresses configured
21# We could have too many addresses to list them in HW
22# (details will be sent in Networks instead)
23#
24#  How could we choose ?
25#
26# Let's try to resolve the name of our server
27
28
29  chomp( $hostn = `uname -n` );
30  if ($hostn) {
31    my $aip;
32    foreach (`ping -s $hostn 10 1`) {
33      unless ( $ip ) {
34        if( /^.*\((\d+\.\d+\.\d+\.\d+)\):.*/ ) {
35          $aip = $1;
36          $ip = $aip  if( exists($ip{$aip}) );
37        }
38      }
39    }
40  }
41
42
43  $common->setHardware({IPADDR => $ip});
44}
45
461;
Note: See TracBrowser for help on using the repository browser.