Subversion Repositories camp_sysinfo_client_3

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

#!/usr/bin/env perl
use warnings;
use strict;  

# Description: Networking for Unix systems

our $VERSION = '1.2';

# Linux network module for sysinfo client
# Author: R. W. Rodolico
# Date:   2016-04-08

# module to get network interface information for Linux systems
# assumes ifconfig is on the system and executable by the user
# NOTE: this takes the ifconfig output and parses it, so changes to 
#       this output invalidates this module

BEGIN {
   push @INC, shift;
}

use library;

exit 1 unless &getOperatingSystem() =~ m/bsd/i;

my $command = &validCommandOnSystem('/sbin/ifconfig');

exit 1 unless $command;

my $CATEGORY = 'network';
# xn0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
# ether 00:16:3e:ff:ff:04
my $regexHWADDR = 'ether\s+([0-9a-f:]+)';
# inet 74.113.60.189 netmask 0xffffffc0 broadcast 74.113.60.191
my $regexINET = 'inet\s*([0-9.]+)[^0-9].*netmask 0x([0-9a-z]+)';
# inet6 addr: fe80::216:3eff:fe1f:ef4f/64 Scope:Link
my $regexINET6 = 'inet6\s*([0-9a-f:]+).*prefixlen\s*(\d+)';
# UP LOOPBACK RUNNING  MTU:16436  Metric:1
my $regexMTU = 'mtu\s([0-9]+)';
my $temp = qx/$command/;
my @temp = split( "\n", $temp );
my $currentIF;
while ( @temp ) {
   my $line = shift @temp;
   next unless $line;
   if ( $line =~ m/^([^ ]+):/) { # if the first character is not a space, starting new entry
      $currentIF = $1;
      if ( $line =~ m/$regexMTU/i ) {
         print "$CATEGORY\t$currentIF\tmtu\t$1\n";
      }
   } elsif ( $line =~ m/$regexHWADDR/i ) {
      print "$CATEGORY\t$currentIF\tmac\t$1\n";
   } elsif ( $line =~ m/$regexINET/i ) {
      print "$CATEGORY\t$currentIF\taddress\t$1\n";
      print "$CATEGORY\t$currentIF\tnetmask\t$2\n";
   } elsif ( $line =~ m/$regexINET6/i )  {
      print "$CATEGORY\t$currentIF\tip6address\t$1\n";
      print "$CATEGORY\t$currentIF\tip6networkbits\t$2\n";
   } elsif ( $line =~ m/$regexMTU/i )  {
      print "$CATEGORY\t$currentIF\tmtu\t$1\n";
   }
}