Subversion Repositories camp_sysinfo_client_3

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 rodolico 1
#!/usr/bin/env perl
2
use warnings;
2 rodolico 3
 
20 rodolico 4
$main::VERSION = '1.0';
5
 
2 rodolico 6
# Linux network module for sysinfo client
7
# Author: R. W. Rodolico
20 rodolico 8
# Date:   2016-04-08
2 rodolico 9
 
10
# module to get network interface information for Linux systems
11
# assumes ifconfig is on the system and executable by the user
12
# NOTE: this takes the ifconfig output and parses it, so changes to 
13
#       this output invalidates this module
14
 
15
BEGIN {
16
   push @INC, shift;
17
}
18
 
19
use library;
20
 
21
my $command = &validCommandOnSystem('/sbin/ifconfig');
22
 
23
exit 1 unless $command;
24
 
25
my $CATEGORY = 'network';
26
# eth1      Link encap:Ethernet  HWaddr 00:16:3E:1F:EF:4F
27
my $regexHWADDR = 'hwaddr[^0-9a-f:]+([0-9a-f:]+)[^0-9a-f:]';
28
# inet addr:10.110.110.2  Bcast:10.110.110.255  Mask:255.255.255.0
29
my $regexINET = 'inet addr:\s*([0-9.]+)[^0-9].*mask:([0-9.]+)';
30
# inet6 addr: fe80::216:3eff:fe1f:ef4f/64 Scope:Link
31
my $regexINET6 = 'inet6 addr: ([0-9a-f:]+)\/([0-9]+)[^0-9]';
32
# UP LOOPBACK RUNNING  MTU:16436  Metric:1
33
my $regexMTU = 'mtu:([0-9]+)[^0-9]';
34
my $temp = qx/$command/;
35
my @temp = split( "\n", $temp );
36
my $currentIF;
37
while ( @temp ) {
38
   $line = shift @temp;
39
   next unless $line;
40
   if ( $line =~ m/^([^ ]+) /) { # if the first character is not a space, starting new entry
41
      $currentIF = $1;
42
      if ( $line =~ m/$regexHWADDR/i ) {
43
         print "$CATEGORY\t$currentIF\tmac\t$1\n";
44
      } else {
45
         print "$CATEGORY\t$currentIF\tmac\tunknown\n";
46
      }
47
   } elsif ( $line =~ m/$regexINET/i ) {
48
      print "$CATEGORY\t$currentIF\taddress\t$1\n";
49
      print "$CATEGORY\t$currentIF\tnetmask\t$2\n";
50
   } elsif ( $line =~ m/$regexINET6/i )  {
51
      print "$CATEGORY\t$currentIF\tip6address\t$1\n";
52
      print "$CATEGORY\t$currentIF\tip6networkbits\t$2\n";
53
   } elsif ( $line =~ m/$regexMTU/i )  {
54
      print "$CATEGORY\t$currentIF\tmtu\t$1\n";
55
   }
56
}