Subversion Repositories camp_sysinfo_client_3

Rev

Rev 237 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
48 rodolico 1
#!/usr/bin/env perl
2
use warnings;
3
use strict;  
4
 
5
# Description: Networking for Unix systems
6
 
7
our $VERSION = '1.2';
8
 
9
# Linux network module for sysinfo client
10
# Author: R. W. Rodolico
11
# Date:   2016-04-08
12
 
13
# module to get network interface information for Linux systems
14
# assumes ifconfig is on the system and executable by the user
15
# NOTE: this takes the ifconfig output and parses it, so changes to 
16
#       this output invalidates this module
17
 
18
BEGIN {
19
   push @INC, shift;
20
}
21
 
22
use library;
23
 
24
exit 1 unless &getOperatingSystem() =~ m/bsd/i;
25
 
26
my $command = &validCommandOnSystem('/sbin/ifconfig');
27
 
28
exit 1 unless $command;
29
 
30
my $CATEGORY = 'network';
31
# xn0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
32
# ether 00:16:3e:ff:ff:04
33
my $regexHWADDR = 'ether\s+([0-9a-f:]+)';
34
# inet 74.113.60.189 netmask 0xffffffc0 broadcast 74.113.60.191
35
my $regexINET = 'inet\s*([0-9.]+)[^0-9].*netmask 0x([0-9a-z]+)';
36
# inet6 addr: fe80::216:3eff:fe1f:ef4f/64 Scope:Link
37
my $regexINET6 = 'inet6\s*([0-9a-f:]+).*prefixlen\s*(\d+)';
38
# UP LOOPBACK RUNNING  MTU:16436  Metric:1
39
my $regexMTU = 'mtu\s([0-9]+)';
40
my $temp = qx/$command/;
41
my @temp = split( "\n", $temp );
42
my $currentIF;
43
while ( @temp ) {
44
   my $line = shift @temp;
45
   next unless $line;
46
   if ( $line =~ m/^([^ ]+):/) { # if the first character is not a space, starting new entry
47
      $currentIF = $1;
48
      if ( $line =~ m/$regexMTU/i ) {
49
         print "$CATEGORY\t$currentIF\tmtu\t$1\n";
50
      }
51
   } elsif ( $line =~ m/$regexHWADDR/i ) {
52
      print "$CATEGORY\t$currentIF\tmac\t$1\n";
53
   } elsif ( $line =~ m/$regexINET/i ) {
54
      print "$CATEGORY\t$currentIF\taddress\t$1\n";
55
      print "$CATEGORY\t$currentIF\tnetmask\t$2\n";
56
   } elsif ( $line =~ m/$regexINET6/i )  {
57
      print "$CATEGORY\t$currentIF\tip6address\t$1\n";
58
      print "$CATEGORY\t$currentIF\tip6networkbits\t$2\n";
59
   } elsif ( $line =~ m/$regexMTU/i )  {
60
      print "$CATEGORY\t$currentIF\tmtu\t$1\n";
61
   }
62
}