20 |
rodolico |
1 |
#!/usr/bin/env perl
|
|
|
2 |
use warnings;
|
26 |
rodolico |
3 |
use strict;
|
2 |
rodolico |
4 |
|
37 |
rodolico |
5 |
# Description: Networking for Unix systems
|
20 |
rodolico |
6 |
|
37 |
rodolico |
7 |
our $VERSION = '1.2';
|
|
|
8 |
|
2 |
rodolico |
9 |
# Linux network module for sysinfo client
|
|
|
10 |
# Author: R. W. Rodolico
|
20 |
rodolico |
11 |
# Date: 2016-04-08
|
2 |
rodolico |
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 |
|
48 |
rodolico |
24 |
exit 1 unless lc ( &getOperatingSystem() ) eq 'linux';
|
|
|
25 |
|
2 |
rodolico |
26 |
my $command = &validCommandOnSystem('/sbin/ifconfig');
|
|
|
27 |
|
|
|
28 |
exit 1 unless $command;
|
|
|
29 |
|
|
|
30 |
my $CATEGORY = 'network';
|
|
|
31 |
# eth1 Link encap:Ethernet HWaddr 00:16:3E:1F:EF:4F
|
|
|
32 |
my $regexHWADDR = 'hwaddr[^0-9a-f:]+([0-9a-f:]+)[^0-9a-f:]';
|
|
|
33 |
# inet addr:10.110.110.2 Bcast:10.110.110.255 Mask:255.255.255.0
|
|
|
34 |
my $regexINET = 'inet addr:\s*([0-9.]+)[^0-9].*mask:([0-9.]+)';
|
|
|
35 |
# inet6 addr: fe80::216:3eff:fe1f:ef4f/64 Scope:Link
|
|
|
36 |
my $regexINET6 = 'inet6 addr: ([0-9a-f:]+)\/([0-9]+)[^0-9]';
|
|
|
37 |
# UP LOOPBACK RUNNING MTU:16436 Metric:1
|
|
|
38 |
my $regexMTU = 'mtu:([0-9]+)[^0-9]';
|
|
|
39 |
my $temp = qx/$command/;
|
|
|
40 |
my @temp = split( "\n", $temp );
|
|
|
41 |
my $currentIF;
|
|
|
42 |
while ( @temp ) {
|
28 |
rodolico |
43 |
my $line = shift @temp;
|
2 |
rodolico |
44 |
next unless $line;
|
|
|
45 |
if ( $line =~ m/^([^ ]+) /) { # if the first character is not a space, starting new entry
|
|
|
46 |
$currentIF = $1;
|
|
|
47 |
if ( $line =~ m/$regexHWADDR/i ) {
|
|
|
48 |
print "$CATEGORY\t$currentIF\tmac\t$1\n";
|
|
|
49 |
} else {
|
|
|
50 |
print "$CATEGORY\t$currentIF\tmac\tunknown\n";
|
|
|
51 |
}
|
|
|
52 |
} elsif ( $line =~ m/$regexINET/i ) {
|
|
|
53 |
print "$CATEGORY\t$currentIF\taddress\t$1\n";
|
|
|
54 |
print "$CATEGORY\t$currentIF\tnetmask\t$2\n";
|
|
|
55 |
} elsif ( $line =~ m/$regexINET6/i ) {
|
|
|
56 |
print "$CATEGORY\t$currentIF\tip6address\t$1\n";
|
|
|
57 |
print "$CATEGORY\t$currentIF\tip6networkbits\t$2\n";
|
|
|
58 |
} elsif ( $line =~ m/$regexMTU/i ) {
|
|
|
59 |
print "$CATEGORY\t$currentIF\tmtu\t$1\n";
|
|
|
60 |
}
|
|
|
61 |
}
|