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 |
|
|
|
24 |
my $command = &validCommandOnSystem('/sbin/ifconfig');
|
|
|
25 |
|
|
|
26 |
exit 1 unless $command;
|
|
|
27 |
|
|
|
28 |
my $CATEGORY = 'network';
|
|
|
29 |
# eth1 Link encap:Ethernet HWaddr 00:16:3E:1F:EF:4F
|
|
|
30 |
my $regexHWADDR = 'hwaddr[^0-9a-f:]+([0-9a-f:]+)[^0-9a-f:]';
|
|
|
31 |
# inet addr:10.110.110.2 Bcast:10.110.110.255 Mask:255.255.255.0
|
|
|
32 |
my $regexINET = 'inet addr:\s*([0-9.]+)[^0-9].*mask:([0-9.]+)';
|
|
|
33 |
# inet6 addr: fe80::216:3eff:fe1f:ef4f/64 Scope:Link
|
|
|
34 |
my $regexINET6 = 'inet6 addr: ([0-9a-f:]+)\/([0-9]+)[^0-9]';
|
|
|
35 |
# UP LOOPBACK RUNNING MTU:16436 Metric:1
|
|
|
36 |
my $regexMTU = 'mtu:([0-9]+)[^0-9]';
|
|
|
37 |
my $temp = qx/$command/;
|
|
|
38 |
my @temp = split( "\n", $temp );
|
|
|
39 |
my $currentIF;
|
|
|
40 |
while ( @temp ) {
|
28 |
rodolico |
41 |
my $line = shift @temp;
|
2 |
rodolico |
42 |
next unless $line;
|
|
|
43 |
if ( $line =~ m/^([^ ]+) /) { # if the first character is not a space, starting new entry
|
|
|
44 |
$currentIF = $1;
|
|
|
45 |
if ( $line =~ m/$regexHWADDR/i ) {
|
|
|
46 |
print "$CATEGORY\t$currentIF\tmac\t$1\n";
|
|
|
47 |
} else {
|
|
|
48 |
print "$CATEGORY\t$currentIF\tmac\tunknown\n";
|
|
|
49 |
}
|
|
|
50 |
} elsif ( $line =~ m/$regexINET/i ) {
|
|
|
51 |
print "$CATEGORY\t$currentIF\taddress\t$1\n";
|
|
|
52 |
print "$CATEGORY\t$currentIF\tnetmask\t$2\n";
|
|
|
53 |
} elsif ( $line =~ m/$regexINET6/i ) {
|
|
|
54 |
print "$CATEGORY\t$currentIF\tip6address\t$1\n";
|
|
|
55 |
print "$CATEGORY\t$currentIF\tip6networkbits\t$2\n";
|
|
|
56 |
} elsif ( $line =~ m/$regexMTU/i ) {
|
|
|
57 |
print "$CATEGORY\t$currentIF\tmtu\t$1\n";
|
|
|
58 |
}
|
|
|
59 |
}
|