#!/usr/bin/env perl # Copyright (c) 2018-2021 Artica Soluciones Tecnologicas S.L. use strict; use warnings; use Scalar::Util qw(looks_like_number); # Call netstat. my @out = `netstat -as 2>/dev/null`; return if ($? != 0 || $#out < 0); my $section = "[Unknown]"; foreach my $line (@out) { chomp($line); # New section. if ($line =~ m/\s*(.*):$/) { $section = $1; next; } # Parse the data. my ($module_name, $data) = ('', ''); if ($line =~ m/(\d+)\s+(.+)$/) { ($module_name, $data) = ($2, $1); } elsif ($line =~ m/\s*(.+):\s+(\d+)$/) { ($module_name, $data) = ($1, $2); } # No data or non-numeric data. next unless looks_like_number($data); print "\n"; print " \n"; print " generic_data_inc\n"; print " Networking\n"; print " $data\n"; print "\n"; }