From 2a93394a9368485e1d5e9a46dd99faedf6a0c048 Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Wed, 20 Feb 2019 05:53:43 -0600 Subject: [PATCH] all good now! --- Parse-Netstat-Search/Makefile.PL | 37 ++++++++++--------- .../lib/Parse/Netstat/Search.pm | 30 ++++++++++++++- Parse-Netstat-Search/t/search.t | 12 ++++++ 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/Parse-Netstat-Search/Makefile.PL b/Parse-Netstat-Search/Makefile.PL index 1590bfe..745423b 100644 --- a/Parse-Netstat-Search/Makefile.PL +++ b/Parse-Netstat-Search/Makefile.PL @@ -4,21 +4,22 @@ use warnings; use ExtUtils::MakeMaker; WriteMakefile( - NAME => 'Parse::Netstat::Search', - AUTHOR => q{Zane C. Bowers-Hadley }, - VERSION_FROM => 'lib/Parse/Netstat/Search.pm', - ABSTRACT_FROM => 'lib/Parse/Netstat/Search.pm', - LICENSE => 'artistic_2', - PL_FILES => {}, - MIN_PERL_VERSION => '5.006', - CONFIGURE_REQUIRES => { - 'ExtUtils::MakeMaker' => '0', - }, - BUILD_REQUIRES => { - 'Test::More' => '0', - 'Net::CIDR' => '0', - 'Error::Helper' => '1.0.0', - }, - dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, - clean => { FILES => 'Parse-Netstat-Search-*' }, -); + NAME => 'Parse::Netstat::Search', + AUTHOR => q{Zane C. Bowers-Hadley }, + VERSION_FROM => 'lib/Parse/Netstat/Search.pm', + ABSTRACT_FROM => 'lib/Parse/Netstat/Search.pm', + LICENSE => 'artistic_2', + PL_FILES => {}, + MIN_PERL_VERSION => '5.006', + CONFIGURE_REQUIRES => { + 'ExtUtils::MakeMaker' => '0', + }, + BUILD_REQUIRES => { + 'Test::More' => '0', + 'Net::CIDR' => '0', + 'Parse::Netstat'=>'0.14', + 'Error::Helper' => '1.0.0', + }, + dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, + clean => { FILES => 'Parse-Netstat-Search-*' }, + ); diff --git a/Parse-Netstat-Search/lib/Parse/Netstat/Search.pm b/Parse-Netstat-Search/lib/Parse/Netstat/Search.pm index 98c6dec..e9eb73b 100644 --- a/Parse-Netstat-Search/lib/Parse/Netstat/Search.pm +++ b/Parse-Netstat-Search/lib/Parse/Netstat/Search.pm @@ -29,13 +29,25 @@ our $VERSION = '0.0.0'; my $search = Parse::Netstat::Search->new(); + $search->set_cidrs( [ '10.0.0.0/24', '192.168.0.0/16' ] ); + my @found=$search->search($res); + + +Two big things to bet aware of is this module does not currently resulve names and this module +does not handle unix sockets. Unix sockets will just be skipped over. =head1 methods =head2 new -=cut +This initiates it. + +No values are taken. + + my $search=Parse::Netstat::Search->new; + +=cut sub new{ my $self={ @@ -63,6 +75,8 @@ Retrieves the CIDR match list. The returned value is an array. + my @CIDRs=$search->get_cidrs; + =cut sub get_cidrs{ @@ -102,6 +116,12 @@ Gets a list of desired protocols. The returned value is a array. +Also if you've passed any named ones to it previously, +this will not return them, but the port number as that +is how they are stored internlly. + + my @protocols=$search->get_protocols; + =cut sub get_protocols{ @@ -120,6 +140,11 @@ Get a list of desired sets. The returned value is a array. +The returned values are all lowercased. Any trailing +or proceeding whitespace will also have been removed. + + my @states=$search->get_states; + =cut sub get_states{ @@ -295,6 +320,9 @@ One value is taken and that is a array ref of CIDRs. Validating in is done by Net::CIDR::cidrvalidate. +If you are using this, you will want to use -n with netstat +as this module currently does not resolve names. + # set the desired CIDRs to the contents of @CIDRs $search->set_cidrs( \@CIDRs ); if ( $search->error ){ diff --git a/Parse-Netstat-Search/t/search.t b/Parse-Netstat-Search/t/search.t index d0a222e..a38666e 100644 --- a/Parse-Netstat-Search/t/search.t +++ b/Parse-Netstat-Search/t/search.t @@ -70,6 +70,18 @@ my $res=[ '0', '1', 'proto' => 'tcp4', 'sendq' => '0' }, + { + 'inode' => '0', + 'address' => 'fffff8004ca0ca00', + 'addr' => '/var/run/dovecot/stats-writer', + 'conn' => 'fffff8004c9ae500', + 'proto' => 'unix', + 'sendq' => '0', + 'type' => 'stream', + 'recvq' => '0', + 'refs' => '0', + 'nextref' => '0' + }, ], } ];