Subversion Repositories camp_sysinfo_client_3

Rev

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

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