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