Compare commits

...

18 Commits

Author SHA1 Message Date
Zane C. B-H 883693ee46 note the use of All and bump to 0.5.0 2021-02-17 23:14:41 -06:00
Zane C. B-H 6023e296a6 now uses All if the array is empty 2021-02-17 22:28:15 -06:00
Zane C. B-H 612d686546 bump to 0.5.0 2021-02-17 22:22:50 -06:00
Zane C. B-H 203d0c7c7d port matching change 2021-02-17 22:10:01 -06:00
Zane C. B-H e289ff3ddb note changes, bump version, and now require 0.2.0 of NC 2019-08-12 05:53:20 -05:00
Zane C. B-H d51a0d91e7 PctMem works now 2019-08-11 22:51:47 -05:00
Zane C. B-H 63764f9a50 add PctMem 2019-08-11 22:36:41 -05:00
Zane C. B-H 43795818ec now works with non-int numbers 2019-08-11 06:05:16 -05:00
Zane C. B-H e84ce182a0 add PctCPU support 2019-08-11 05:50:13 -05:00
Zane C. B-H 6e8c8f0dcd update the manifest 2019-08-11 05:04:26 -05:00
Zane C. B-H f71b83f6cc now requires the newest version of Net::Connection and add WChan 2019-08-11 05:02:37 -05:00
Zane C. B-H f6103c5bd0 note various changes to 0.3.0, bump version, assorted doc cleanup 2019-08-09 07:46:24 -05:00
Zane C. B-H 724476cd0b add a second missing depend 2019-08-09 06:39:07 -05:00
Zane C. B-H 51fc444a92 add a missing dependency 2019-08-09 06:33:15 -05:00
Zane C. B-H ac843c2ee9 Proc::ProcessTable->table returns a array ref and not a array 2019-08-07 06:04:33 -05:00
Zane C. B-H ddf4ab43b1 add the command match 2019-08-07 05:42:02 -05:00
Zane C. B-H f9d87b2c12 correct a test file name and add tests for PID 2019-08-07 04:05:30 -05:00
Zane C. B-H 9b1f568591 add PID support 2019-08-07 04:02:20 -05:00
20 changed files with 1786 additions and 13 deletions

View File

@ -1,5 +1,16 @@
Revision history for Net-Connection-Match
0.5.0 2021-02-17:23:30
- Add All.
- Use all if no checks are specified.
0.4.0 2019-08-12/05:50
- Add PctCPU, PctMem, and WChan.
0.3.0 2019-08-09/07:40
- Add a missing depend for Error::Helper.
- Add support for regexp command searches.
0.2.0 2019-08-06/05:30
- Misc. POD fixes.
- Add RegexPTR support.

View File

@ -1,12 +1,16 @@
Changes
lib/Net/Connection/Match.pm
lib/Net/Connection/Match/All.pm
lib/Net/Connection/Match/CIDR.pm
lib/Net/Connection/Match/Command.pm
lib/Net/Connection/Match/PctCPU.pm
lib/Net/Connection/Match/Ports.pm
lib/Net/Connection/Match/Protos.pm
lib/Net/Connection/Match/PTR.pm
lib/Net/Connection/Match/RegexPTR.pm
lib/Net/Connection/Match/States.pm
lib/Net/Connection/Match/UID.pm
lib/Net/Connection/Match/WChan.pm
Makefile.PL
MANIFEST This list of files
README
@ -16,6 +20,15 @@ t/02-load.t
t/03-load.t
t/04-load.t
t/05-load.t
t/06-load.t
t/07-load.t
t/08-load.t
t/09-load.t
t/10-load.t
t/11-load.t
t/12-load.t
t/13-load.t
t/14-load.t
t/CIDR.t
t/PTR.t
t/Protos.t

View File

@ -19,8 +19,10 @@ WriteMakefile(
},
PREREQ_PM => {
'Net::CIDR'=>'0.20',
'Net::Connection'=>'0.0.0',
'Net::Connection'=>'0.2.0',
'Net::DNS'=>'1.20',
'Proc::ProcessTable' => '0.59',
'Error::Helper' => '1.0.0',
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Net-Connection-Match-*' },

View File

@ -6,10 +6,16 @@ object mathes a series of checks.
Currently can do matching based off of the following.
* CIDR
* Command
* PctCPU
* Ports
* Protocol
* State
* RegexPTR
* PTR
* UID
* Username
* WChan
use Net::Connection::Match;
use Net::Connection;

View File

@ -11,11 +11,11 @@ Net::Connection::Match - Runs a stack of checks to match Net::Connection objects
=head1 VERSION
Version 0.2.0
Version 0.5.0
=cut
our $VERSION = '0.2.0';
our $VERSION = '0.5.0';
=head1 SYNOPSIS
@ -78,7 +78,8 @@ our $VERSION = '0.2.0';
This initializes a new check object.
It takes one value and thht is a hash ref with the key checks.
This is a array of hashes.
This is a array of hashes. If the array is empty, it will default
to using the All test.
If new fails, it will die.
@ -123,7 +124,12 @@ sub new{
}
# Will never match anything.
if ( ! defined $args{checks}[0] ){
die ('Nothing in the checks array');
$args{checks}[0] = {
type => 'All',
invert => 0,
args => {}
};
}
if ( ref( %{ $args{checks}[0] } ) eq 'HASH' ){
die ('The first item in the checks array is not a hash');
@ -144,9 +150,6 @@ sub new{
};
bless $self;
# will hold the created check objects
my @checks;
# Loads up each check or dies if it fails to.
my $check_int=0;
while( defined( $args{checks}[$check_int] ) ){

View File

@ -0,0 +1,164 @@
package Net::Connection::Match::All;
use 5.006;
use strict;
use warnings;
=head1 NAME
Net::Connection::Match::All - Matches everything.
=head1 VERSION
Version 0.0.0
=cut
our $VERSION = '0.0.0';
=head1 SYNOPSIS
use Net::Connection::Match::All;
use Net::Connection;
my $connection_args={
foreign_host=>'10.0.0.1',
foreign_port=>'22',
local_host=>'10.0.0.2',
local_port=>'12322',
proto=>'tcp4',
state=>'ESTABLISHED',
pid=>0,
};
my $conn=Net::Connection->new( $connection_args );
my $checker=Net::Connection::Match::All->new;
if ( $checker->match( $conn ) ){
print "It matches.\n";
}
=head1 METHODS
=head2 new
None taken.
my $checker=Net::Connection::Match::All->new( );
=cut
sub new{
my $self = {
};
bless $self;
return $self;
}
=head2 match
Returns 1.
if ( $checker->match( $conn ) ){
print "The connection matches.\n";
}
=cut
sub match{
return 1;
}
=head1 AUTHOR
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-net-connection-match at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Match>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Net::Connection::Match
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker (report bugs here)
L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Match>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Net-Connection-Match>
=item * CPAN Ratings
L<https://cpanratings.perl.org/d/Net-Connection-Match>
=item * Search CPAN
L<https://metacpan.org/release/Net-Connection-Match>
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2019 Zane C. Bowers-Hadley.
This program is free software; you can redistribute it and/or modify it
under the terms of the the Artistic License (2.0). You may obtain a
copy of the full license at:
L<http://www.perlfoundation.org/artistic_license_2_0>
Any use, modification, and distribution of the Standard or Modified
Versions is governed by this Artistic License. By using, modifying or
distributing the Package, you accept this license. Do not use, modify,
or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made
by someone other than you, you are nevertheless required to ensure that
your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service
mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge
patent license to make, have made, use, offer to sell, sell, import and
otherwise transfer the Package with respect to any patent claims
licensable by the Copyright Holder that are necessarily infringed by the
Package. If you institute patent litigation (including a cross-claim or
counterclaim) against any party alleging that the Package constitutes
direct or contributory patent infringement, then this Artistic License
to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=cut
1; # End of Net::Connection::Match

View File

@ -0,0 +1,268 @@
package Net::Connection::Match::Command;
use 5.006;
use strict;
use warnings;
use Proc::ProcessTable;
=head1 NAME
Net::Connection::Match::Command - Check if the process command matches fix regexp for a Net::Connection object.
=head1 VERSION
Version 0.1.0
=cut
our $VERSION = '0.1.0';
=head1 SYNOPSIS
use Net::Connection::Match::Command;
use Net::Connection;
my $connection_args={
foreign_host=>'10.0.0.1',
foreign_port=>'22',
local_host=>'10.0.0.2',
local_port=>'12322',
proto=>'tcp4',
state=>'ESTABLISHED',
pid=>0,
};
my $conn=Net::Connection->new( $connection_args );
my %args=(
commands=>[
'kernel',
],
);
my $checker=Net::Connection::Match::Command->new( \%args );
if ( $checker->match( $conn ) ){
print "It matches.\n";
}
=head1 METHODS
=head2 new
This intiates the object.
The key in the hash ref commands is a array
that holds regular expressions to match against
the command line or fname(in case of blank command
line). At least one value must be defined.
If the new method fails, it dies.
my %args=(
commands=>[
'kernel',
],
);
my $checker=Net::Connection::Match::Command->new( \%args );
=cut
sub new{
my %args;
if(defined($_[1])){
%args= %{$_[1]};
};
# run some basic checks to make sure we have the minimum stuff required to work
if ( ! defined( $args{commands} ) ){
die ('No commands key specified in the argument hash');
}
if ( ref( \$args{commands} ) eq 'ARRAY' ){
die ('The commands key is not a array');
}
if ( ! defined $args{commands}[0] ){
die ('Nothing defined in the commands array');
}
my $self = {
commands=>$args{commands},
};
bless $self;
return $self;
}
=head2 match
Checks if a single Net::Connection object matches the stack.
One argument is taken and that is a Net::Connection object.
The returned value is a boolean.
if ( $checker->match( $conn ) ){
print "The connection matches.\n";
}
=cut
sub match{
my $self=$_[0];
my $object=$_[1];
if ( !defined( $object ) ){
return 0;
}
if ( ref( $object ) ne 'Net::Connection' ){
return 0;
}
my $conn_pid=$object->pid;
# don't bother proceeding, the object won't match ever
# as it does not have a PID
if ( ! defined( $conn_pid ) ){
return 0;
}
my $loop=0;
my $command;
if ( ! defined( $object->proc ) ){
# go through each proc and look for a matching pid
my $proctable=Proc::ProcessTable->new;
my $procs=$proctable->table;
my $proc_int=0;
my $loop=1;
while (
$loop &&
defined( $procs->[$proc_int] )
){
if ( $conn_pid eq $procs->[$proc_int]->{pid} ){
$command=$procs->[$proc_int]->cmndline;
# '' means it is a kernel process
if ( $command =~ /^$/ ){
$command='['.$procs->[$proc_int]->fname.']';
}
# exit the loop as we found it
$loop=0;
}
$proc_int++;
}
}else{
$command=$object->proc;
}
# likely a dead connection that is handing around...
# or disappeared since grabbing the connection list
# and starting processing
if ( !defined( $command ) ){
return 0;
}
# check each command regex and see if any of them match
foreach my $regex ( @{ $self->{commands} } ){
if ( $command =~ /$regex/ ){
return 1;
}
}
return 0;
}
=head1 AUTHOR
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-net-connection-match at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Match>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Net::Connection::Match
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker (report bugs here)
L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Match>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Net-Connection-Match>
=item * CPAN Ratings
L<https://cpanratings.perl.org/d/Net-Connection-Match>
=item * Search CPAN
L<https://metacpan.org/release/Net-Connection-Match>
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2019 Zane C. Bowers-Hadley.
This program is free software; you can redistribute it and/or modify it
under the terms of the the Artistic License (2.0). You may obtain a
copy of the full license at:
L<http://www.perlfoundation.org/artistic_license_2_0>
Any use, modification, and distribution of the Standard or Modified
Versions is governed by this Artistic License. By using, modifying or
distributing the Package, you accept this license. Do not use, modify,
or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made
by someone other than you, you are nevertheless required to ensure that
your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service
mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge
patent license to make, have made, use, offer to sell, sell, import and
otherwise transfer the Package with respect to any patent claims
licensable by the Copyright Holder that are necessarily infringed by the
Package. If you institute patent litigation (including a cross-claim or
counterclaim) against any party alleging that the Package constitutes
direct or contributory patent infringement, then this Artistic License
to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=cut
1; # End of Net::Connection::Match

View File

@ -0,0 +1,266 @@
package Net::Connection::Match::PID;
use 5.006;
use strict;
use warnings;
=head1 NAME
Net::Connection::Match::PID - Check if the PID of a connection matches.
=head1 VERSION
Version 0.0.0
=cut
our $VERSION = '0.0.0';
=head1 SYNOPSIS
use Net::Connection::Match::PID;
use Net::Connection;
my $connection_args={
foreign_host=>'10.0.0.1',
foreign_port=>'22',
local_host=>'10.0.0.2',
local_port=>'12322',
proto=>'tcp4',
state=>'ESTABLISHED',
pid=>0,
};
my $conn=Net::Connection->new( $connection_args );
my %args=(
pids=>[
0,
'>1000',
],
);
my $checker=Net::Connection::Match::PID->new( \%args );
if ( $checker->match( $conn ) ){
print "It matches.\n";
}
=head1 METHODS
=head2 new
This intiates the object.
It takes a hash reference with one key. One key is required and
that is 'pids', which is a array of pids to match.
The PID values can be prefixed with the equalities below for doing
additional comparisons.
<
<=
>
>=
Atleast one PID must be specified.
If the new method fails, it dies.
my %args=(
pids=>[
0,
'>1000',
],
);
my $checker=Net::Connection::Match::PID->new( \%args );
=cut
sub new{
my %args;
if(defined($_[1])){
%args= %{$_[1]};
};
# run some basic checks to make sure we have the minimum stuff required to work
if ( ! defined( $args{pids} ) ){
die ('No pids key specified in the argument hash');
}
if ( ref( \$args{pids} ) eq 'ARRAY' ){
die ('The pids key is not a array');
}
if ( ! defined $args{pids}[0] ){
die ('Nothing defined in the pids array');
}
my $self = {
pids=>$args{pids},
};
bless $self;
return $self;
}
=head2 match
Checks if a single Net::Connection object matches the stack.
One argument is taken and that is a Net::Connection object.
The returned value is a boolean.
if ( $checker->match( $conn ) ){
print "The connection matches.\n";
}
=cut
sub match{
my $self=$_[0];
my $object=$_[1];
if ( !defined( $object ) ){
return 0;
}
if ( ref( $object ) ne 'Net::Connection' ){
return 0;
}
my $conn_pid=$object->pid;
# don't bother proceeding, the object won't match ever
# as it does not have a PID
if ( ! defined( $conn_pid ) ){
return 0;
}
# use while as foreach will reference the value
my $pid_int=0;
while (defined( $self->{pids}[$pid_int] )){
my $pid=$self->{pids}[$pid_int];
if (
( $pid =~ /^[0-9]+$/ ) &&
( $pid eq $conn_pid )
){
return 1;
}elsif( $pid =~ /^\<\=[0-9]+$/ ){
$pid=~s/^\<\=//;
if ( $conn_pid <= $pid ){
return 1;
}
}elsif( $pid =~ /^\<[0-9]+$/ ){
$pid=~s/^\<//;
if ( $conn_pid < $pid ){
return 1;
}
}elsif( $pid =~ /^\>\=[0-9]+$/ ){
$pid=~s/^\>\=//;
if ( $conn_pid >= $pid ){
return 1;
}
}elsif( $pid =~ /^\>[0-9]+$/ ){
$pid=~s/^\>//;
if ( $conn_pid > $pid ){
return 1;
}
}
$pid_int++;
}
return 0;
}
=head1 AUTHOR
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-net-connection-match at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Match>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Net::Connection::Match
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker (report bugs here)
L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Match>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Net-Connection-Match>
=item * CPAN Ratings
L<https://cpanratings.perl.org/d/Net-Connection-Match>
=item * Search CPAN
L<https://metacpan.org/release/Net-Connection-Match>
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2019 Zane C. Bowers-Hadley.
This program is free software; you can redistribute it and/or modify it
under the terms of the the Artistic License (2.0). You may obtain a
copy of the full license at:
L<http://www.perlfoundation.org/artistic_license_2_0>
Any use, modification, and distribution of the Standard or Modified
Versions is governed by this Artistic License. By using, modifying or
distributing the Package, you accept this license. Do not use, modify,
or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made
by someone other than you, you are nevertheless required to ensure that
your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service
mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge
patent license to make, have made, use, offer to sell, sell, import and
otherwise transfer the Package with respect to any patent claims
licensable by the Copyright Holder that are necessarily infringed by the
Package. If you institute patent litigation (including a cross-claim or
counterclaim) against any party alleging that the Package constitutes
direct or contributory patent infringement, then this Artistic License
to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=cut
1; # End of Net::Connection::Match

View File

@ -0,0 +1,301 @@
package Net::Connection::Match::PctCPU;
use 5.006;
use strict;
use warnings;
use Proc::ProcessTable;
=head1 NAME
Net::Connection::Match::PctCPU - Check if the pctcpu of a process matches for the process that has the connection.
=head1 VERSION
Version 0.0.0
=cut
our $VERSION = '0.0.0';
=head1 SYNOPSIS
use Net::Connection::Match::PctCPU;
use Net::Connection;
my $connection_args={
foreign_host=>'10.0.0.1',
foreign_port=>'22',
local_host=>'10.0.0.2',
local_port=>'12322',
proto=>'tcp4',
state=>'ESTABLISHED',
pid=>0,
pctcpu=>'5.03',
};
my $conn=Net::Connection->new( $connection_args );
my %args=(
pctcpus=>[
'>1',
],
);
my $checker=Net::Connection::Match::PctCPU->new( \%args );
if ( $checker->match( $conn ) ){
print "It matches.\n";
}
=head1 METHODS
=head2 new
This intiates the object.
It takes a hash reference with one key. One key is required and
that is 'pctcpus', which is a array of pctcpu value.
The pctcpu values can be prefixed with the equalities below for doing
additional comparisons.
<
<=
>
>=
Atleast one must be specified.
If the new method fails, it dies.
my %args=(
pctcpus=>[
'>1',
],
);
my $checker=Net::Connection::Match::PctCPU->new( \%args );
=cut
sub new{
my %args;
if(defined($_[1])){
%args= %{$_[1]};
};
# run some basic checks to make sure we have the minimum stuff required to work
if ( ! defined( $args{pctcpus} ) ){
die ('No pctcpus key specified in the argument hash');
}
if ( ref( \$args{pctcpus} ) eq 'ARRAY' ){
die ('The pctcpus key is not a array');
}
if ( ! defined $args{pctcpus}[0] ){
die ('Nothing defined in the pctcpus array');
}
my $self = {
pctcpus=>$args{pctcpus},
};
bless $self;
return $self;
}
=head2 match
Checks if a single Net::Connection object matches the stack.
One argument is taken and that is a Net::Connection object.
The returned value is a boolean.
if ( $checker->match( $conn ) ){
print "The connection matches.\n";
}
=cut
sub match{
my $self=$_[0];
my $object=$_[1];
if ( !defined( $object ) ){
return 0;
}
if ( ref( $object ) ne 'Net::Connection' ){
return 0;
}
my $conn_pid=$object->pid;
# don't bother proceeding, the object won't match ever
# as it does not have a PID
if ( ! defined( $conn_pid ) ){
return 0;
}
my $loop=0;
my $pctcpu;
if ( ! defined( $object->proc ) ){
# go through each proc and look for a matching pid
my $proctable=Proc::ProcessTable->new;
my $procs=$proctable->table;
my $proc_int=0;
my $loop=1;
while (
$loop &&
defined( $procs->[$proc_int] )
){
if ( $conn_pid eq $procs->[$proc_int]->{pid} ){
$pctcpu=$procs->[$proc_int]->{pctcpu};
# exit the loop as we found it
$loop=0;
}
$proc_int++;
}
}else{
$pctcpu=$object->pctcpu;
}
# likely a dead connection that is handing around...
# or disappeared since grabbing the connection list
# and starting processing
if ( !defined( $pctcpu ) ){
return 0;
}
# use while as foreach will reference the value
my $pctcpu_int=0;
while (defined( $self->{pctcpus}[$pctcpu_int] )){
my $value=$self->{pctcpus}[$pctcpu_int];
if (
( $value =~ /^[0-9.]+$/ ) &&
( $value eq $pctcpu )
){
return 1;
}elsif( $value =~ /^\<\=[0-9.]+$/ ){
$value=~s/^\<\=//;
if ( $value <= $pctcpu ){
return 1;
}
}elsif( $value =~ /^\<[0-9.]+$/ ){
$value=~s/^\<//;
if ( $pctcpu < $value ){
return 1;
}
}elsif( $value =~ /^\>\=[0-9.]+$/ ){
$value=~s/^\>\=//;
if ( $pctcpu >= $value ){
return 1;
}
}elsif( $value =~ /^\>[0-9.]+$/ ){
$value=~s/^\>//;
if ( $pctcpu > $value ){
return 1;
}
}
$pctcpu_int++;
}
return 0;
}
=head1 AUTHOR
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-net-connection-match at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Match>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Net::Connection::Match
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker (report bugs here)
L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Match>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Net-Connection-Match>
=item * CPAN Ratings
L<https://cpanratings.perl.org/d/Net-Connection-Match>
=item * Search CPAN
L<https://metacpan.org/release/Net-Connection-Match>
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2019 Zane C. Bowers-Hadley.
This program is free software; you can redistribute it and/or modify it
under the terms of the the Artistic License (2.0). You may obtain a
copy of the full license at:
L<http://www.perlfoundation.org/artistic_license_2_0>
Any use, modification, and distribution of the Standard or Modified
Versions is governed by this Artistic License. By using, modifying or
distributing the Package, you accept this license. Do not use, modify,
or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made
by someone other than you, you are nevertheless required to ensure that
your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service
mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge
patent license to make, have made, use, offer to sell, sell, import and
otherwise transfer the Package with respect to any patent claims
licensable by the Copyright Holder that are necessarily infringed by the
Package. If you institute patent litigation (including a cross-claim or
counterclaim) against any party alleging that the Package constitutes
direct or contributory patent infringement, then this Artistic License
to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=cut
1; # End of Net::Connection::Match

View File

@ -0,0 +1,311 @@
package Net::Connection::Match::PctMem;
use 5.006;
use strict;
use warnings;
use Proc::ProcessTable;
=head1 NAME
Net::Connection::Match::PctMem - Check if the pctmem of a process matches for the process that has the connection.
=head1 VERSION
Version 0.0.0
=cut
our $VERSION = '0.0.0';
=head1 SYNOPSIS
use Net::Connection::Match::PctMem;
use Net::Connection;
my $connection_args={
foreign_host=>'10.0.0.1',
foreign_port=>'22',
local_host=>'10.0.0.2',
local_port=>'12322',
proto=>'tcp4',
state=>'ESTABLISHED',
pid=>0,
pctmem=>'5.03',
};
my $conn=Net::Connection->new( $connection_args );
my %args=(
pctmems=>[
'>1',
],
);
my $checker=Net::Connection::Match::PctMem->new( \%args );
if ( $checker->match( $conn ) ){
print "It matches.\n";
}
=head1 METHODS
=head2 new
This intiates the object.
It takes a hash reference with one key. One key is required and
that is 'pctmems', which is a array of pctmem value.
The pctmem values can be prefixed with the equalities below for doing
additional comparisons.
<
<=
>
>=
Atleast one must be specified.
If the new method fails, it dies.
my %args=(
pctmems=>[
'>1',
],
);
my $checker=Net::Connection::Match::PctMem->new( \%args );
=cut
sub new{
my %args;
if(defined($_[1])){
%args= %{$_[1]};
};
# run some basic checks to make sure we have the minimum stuff required to work
if ( ! defined( $args{pctmems} ) ){
die ('No pctcpus key specified in the argument hash');
}
if ( ref( \$args{pctmems} ) eq 'ARRAY' ){
die ('The pctmems key is not a array');
}
if ( ! defined $args{pctmems}[0] ){
die ('Nothing defined in the pctmems array');
}
my $self = {
pctmems=>$args{pctmems},
};
bless $self;
if ( $^O =~ /bsd/ ){
my $physmem=`/sbin/sysctl -a hw.physmem`;
chomp( $physmem );
$physmem=~s/^.*\: //;
$self->{physmem}=$physmem;
}
return $self;
}
=head2 match
Checks if a single Net::Connection object matches the stack.
One argument is taken and that is a Net::Connection object.
The returned value is a boolean.
if ( $checker->match( $conn ) ){
print "The connection matches.\n";
}
=cut
sub match{
my $self=$_[0];
my $object=$_[1];
if ( !defined( $object ) ){
return 0;
}
if ( ref( $object ) ne 'Net::Connection' ){
return 0;
}
my $conn_pid=$object->pid;
# don't bother proceeding, the object won't match ever
# as it does not have a PID
if ( ! defined( $conn_pid ) ){
return 0;
}
my $loop=0;
my $pctmem;
if ( ! defined( $object->proc ) ){
# go through each proc and look for a matching pid
my $proctable=Proc::ProcessTable->new;
my $procs=$proctable->table;
my $proc_int=0;
my $loop=1;
while (
$loop &&
defined( $procs->[$proc_int] )
){
if ( $conn_pid eq $procs->[$proc_int]->{pid} ){
if ($^O =~ /bsd/){
$pctmem= (( $procs->[ $proc_int ]->{rssize} * 1024 * 4 ) / $self->{physmem}) * 100;
}else{
$pctmem=$procs->[$proc_int]->{pctmem};
}
# exit the loop as we found it
$loop=0;
}
$proc_int++;
}
}else{
$pctmem=$object->pctmem;
}
# likely a dead connection that is handing around...
# or disappeared since grabbing the connection list
# and starting processing
if ( !defined( $pctmem ) ){
return 0;
}
# use while as foreach will reference the value
my $pctmem_int=0;
while (defined( $self->{pctmems}[$pctmem_int] )){
my $value=$self->{pctmems}[$pctmem_int];
if (
( $value =~ /^[0-9.]+$/ ) &&
( $value eq $pctmem )
){
return 1;
}elsif( $value =~ /^\<\=[0-9.]+$/ ){
$value=~s/^\<\=//;
if ( $value <= $pctmem ){
return 1;
}
}elsif( $value =~ /^\<[0-9.]+$/ ){
$value=~s/^\<//;
if ( $pctmem < $value ){
return 1;
}
}elsif( $value =~ /^\>\=[0-9.]+$/ ){
$value=~s/^\>\=//;
if ( $pctmem >= $value ){
return 1;
}
}elsif( $value =~ /^\>[0-9.]+$/ ){
$value=~s/^\>//;
if ( $pctmem > $value ){
return 1;
}
}
$pctmem_int++;
}
return 0;
}
=head1 AUTHOR
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-net-connection-match at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Match>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Net::Connection::Match
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker (report bugs here)
L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Match>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Net-Connection-Match>
=item * CPAN Ratings
L<https://cpanratings.perl.org/d/Net-Connection-Match>
=item * Search CPAN
L<https://metacpan.org/release/Net-Connection-Match>
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2019 Zane C. Bowers-Hadley.
This program is free software; you can redistribute it and/or modify it
under the terms of the the Artistic License (2.0). You may obtain a
copy of the full license at:
L<http://www.perlfoundation.org/artistic_license_2_0>
Any use, modification, and distribution of the Standard or Modified
Versions is governed by this Artistic License. By using, modifying or
distributing the Package, you accept this license. Do not use, modify,
or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made
by someone other than you, you are nevertheless required to ensure that
your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service
mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge
patent license to make, have made, use, offer to sell, sell, import and
otherwise transfer the Package with respect to any patent claims
licensable by the Copyright Holder that are necessarily infringed by the
Package. If you institute patent litigation (including a cross-claim or
counterclaim) against any party alleging that the Package constitutes
direct or contributory patent infringement, then this Artistic License
to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=cut
1; # End of Net::Connection::Match

View File

@ -129,10 +129,8 @@ sub new{
my $ports_int=0;
if ( defined( $args{ports} ) ){
while (defined( $args{ports}[$ports_int] )) {
if ( $args{ports}[$ports_int] =~ /^[0-9]+$/ ){
if ( $args{ports}[$ports_int] =~ /^[0-9\*]+$/ ){
$self->{ports}{ $args{ports}[$ports_int] }= $args{ports}[$ports_int];
}elsif( $args{ports}[$ports_int] =~ /^\*$/ ){
$self->{ports}{'*'}='*';
}else{
my $port_number=(getservbyname( $args{ports}[$ports_int] , '' ))[2];
@ -224,13 +222,13 @@ sub match{
my $fport=$object->foreign_port;
# If either are non-numeric, resolve them if possible
if ( $lport !~ /^[0-9]+$/ ){
if ( $lport !~ /^[0-9\*]+$/ ){
my $lport_number=(getservbyname( $lport , '' ))[2];
if ( defined( $lport_number ) ){
$lport=$lport_number;
}
}
if ( $fport !~ /^[0-9]+$/ ){
if ( $fport !~ /^[0-9\*]+$/ ){
my $fport_number=(getservbyname( $fport , '' ))[2];
if ( defined( $fport_number ) ){
$fport=$fport_number;

View File

@ -0,0 +1,266 @@
package Net::Connection::Match::WChan;
use 5.006;
use strict;
use warnings;
use Proc::ProcessTable;
=head1 NAME
Net::Connection::Match::WChan - Check if the process wait channel matches fix regexp for a Net::Connection object.
=head1 VERSION
Version 0.0.0
=cut
our $VERSION = '0.0.0';
=head1 SYNOPSIS
use Net::Connection::Match::WChan;
use Net::Connection;
my $connection_args={
foreign_host=>'10.0.0.1',
foreign_port=>'22',
local_host=>'10.0.0.2',
local_port=>'12322',
proto=>'tcp4',
state=>'ESTABLISHED',
pid=>0,
wchan=>'sigwait',
};
my $conn=Net::Connection->new( $connection_args );
my %args=(
wchanss=>[
'sleep',
'sigwait',
],
);
my $checker=Net::Connection::Match::WChan->new( \%args );
if ( $checker->match( $conn ) ){
print "It matches.\n";
}
=head1 METHODS
=head2 new
This intiates the object.
The key in the hash ref commands is a array
that holds regular expressions to match against
the wait channel.
If the new method fails, it dies.
my %args=(
wchans=>[
'kernel',
],
);
my $checker=Net::Connection::Match::WChan->new( \%args );
=cut
sub new{
my %args;
if(defined($_[1])){
%args= %{$_[1]};
};
# run some basic checks to make sure we have the minimum stuff required to work
if ( ! defined( $args{wchans} ) ){
die ('No wchans key specified in the argument hash');
}
if ( ref( \$args{wchans} ) eq 'ARRAY' ){
die ('The wchans key is not a array');
}
if ( ! defined $args{wchans}[0] ){
die ('Nothing defined in the commands array');
}
my $self = {
wchans=>$args{wchans},
};
bless $self;
return $self;
}
=head2 match
Checks if a single Net::Connection object matches the stack.
One argument is taken and that is a Net::Connection object.
The returned value is a boolean.
if ( $checker->match( $conn ) ){
print "The connection matches.\n";
}
=cut
sub match{
my $self=$_[0];
my $object=$_[1];
if ( !defined( $object ) ){
return 0;
}
if ( ref( $object ) ne 'Net::Connection' ){
return 0;
}
my $conn_pid=$object->pid;
# don't bother proceeding, the object won't match ever
# as it does not have a PID
if ( ! defined( $conn_pid ) ){
return 0;
}
my $loop=0;
my $wchan;
if ( ! defined( $object->proc ) ){
# go through each proc and look for a matching pid
my $proctable=Proc::ProcessTable->new;
my $procs=$proctable->table;
my $proc_int=0;
my $loop=1;
while (
$loop &&
defined( $procs->[$proc_int] )
){
if ( $conn_pid eq $procs->[$proc_int]->{pid} ){
$wchan=$procs->[$proc_int]->wchan;
# exit the loop as we found it
$loop=0;
}
$proc_int++;
}
}else{
$wchan=$object->wchan;
}
# likely a dead connection that is handing around...
# or disappeared since grabbing the connection list
# and starting processing
if ( !defined( $wchan ) ){
return 0;
}
# check each command regex and see if any of them match
foreach my $regex ( @{ $self->{wchans} } ){
if ( $wchan =~ /$regex/ ){
return 1;
}
}
return 0;
}
=head1 AUTHOR
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-net-connection-match at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Match>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Net::Connection::Match
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker (report bugs here)
L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Match>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Net-Connection-Match>
=item * CPAN Ratings
L<https://cpanratings.perl.org/d/Net-Connection-Match>
=item * Search CPAN
L<https://metacpan.org/release/Net-Connection-Match>
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2019 Zane C. Bowers-Hadley.
This program is free software; you can redistribute it and/or modify it
under the terms of the the Artistic License (2.0). You may obtain a
copy of the full license at:
L<http://www.perlfoundation.org/artistic_license_2_0>
Any use, modification, and distribution of the Standard or Modified
Versions is governed by this Artistic License. By using, modifying or
distributing the Package, you accept this license. Do not use, modify,
or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made
by someone other than you, you are nevertheless required to ensure that
your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service
mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge
patent license to make, have made, use, offer to sell, sell, import and
otherwise transfer the Package with respect to any patent claims
licensable by the Copyright Holder that are necessarily infringed by the
Package. If you institute patent litigation (including a cross-claim or
counterclaim) against any party alleging that the Package constitutes
direct or contributory patent infringement, then this Artistic License
to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=cut
1; # End of Net::Connection::Match

View File

@ -0,0 +1,13 @@
#!perl -T
use 5.006;
use strict;
use warnings;
use Test::More;
plan tests => 1;
BEGIN {
use_ok( 'Net::Connection::Match::PID' ) || print "Bail out!\n";
}
diag( "Testing Net::Connection::Match::PID $Net::Connection::Match::PID::VERSION, Perl $], $^X" );

View File

@ -0,0 +1,13 @@
#!perl -T
use 5.006;
use strict;
use warnings;
use Test::More;
plan tests => 1;
BEGIN {
use_ok( 'Net::Connection::Match::Command' ) || print "Bail out!\n";
}
diag( "Testing Net::Connection::Match::Command $Net::Connection::Match::Command::VERSION, Perl $], $^X" );

View File

@ -0,0 +1,13 @@
#!perl -T
use 5.006;
use strict;
use warnings;
use Test::More;
plan tests => 1;
BEGIN {
use_ok( 'Net::Connection::Match::WChan' ) || print "Bail out!\n";
}
diag( "Testing Net::Connection::Match::WChan $Net::Connection::Match::WChan::VERSION, Perl $], $^X" );

View File

@ -0,0 +1,13 @@
#!perl -T
use 5.006;
use strict;
use warnings;
use Test::More;
plan tests => 1;
BEGIN {
use_ok( 'Net::Connection::Match::PctCPU' ) || print "Bail out!\n";
}
diag( "Testing Net::Connection::Match::PctCPU $Net::Connection::Match::PctCPU::VERSION, Perl $], $^X" );

View File

@ -0,0 +1,13 @@
#!perl -T
use 5.006;
use strict;
use warnings;
use Test::More;
plan tests => 1;
BEGIN {
use_ok( 'Net::Connection::Match::PctMem' ) || print "Bail out!\n";
}
diag( "Testing Net::Connection::Match::PctMem $Net::Connection::Match::PctMem::VERSION, Perl $], $^X" );

View File

@ -0,0 +1,13 @@
#!perl -T
use 5.006;
use strict;
use warnings;
use Test::More;
plan tests => 1;
BEGIN {
use_ok( 'Net::Connection::Match::All' ) || print "Bail out!\n";
}
diag( "Testing Net::Connection::Match::All $Net::Connection::Match::All::VERSION, Perl $], $^X" );

View File

@ -0,0 +1,86 @@
#!perl -T
use 5.006;
use strict;
use warnings;
use Test::More;
use Net::Connection;
BEGIN {
use_ok( 'Net::Connection::Match::PID' ) || print "Bail out!\n";
}
my $connection_args={
foreign_host=>'10.0.0.1',
foreign_port=>'22',
local_host=>'10.0.0.2',
local_port=>'12322',
proto=>'tcp4',
state=>'LISTEN',
pid=>0,
};
my %args=(
pids=>[
'0',
'>1000',
],
);
my $checker;
# makes sure we error with empty args
my $worked=0;
eval{
$checker=Net::Connection::Match::PID->new();
$worked=1;
};
ok( $worked eq '0', 'empty init check') or diag('Calling new with empty args worked');
# makes sure we can init with good args
$worked=0;
eval{
$checker=Net::Connection::Match::PID->new( \%args );
$worked=1;
};
ok( $worked eq '1', 'init check') or diag('Calling Net::Connection::Match::PID->new resulted in... '.$@);
# make sure it will not accept null input
my $returned=1;
eval{
$returned=$checker->match;
};
ok( $returned eq '0', 'undef match check') or diag('match accepted undefined input');
# make sure it will not accept a improper ref type
$returned=1;
eval{
$returned=$checker->match($checker);
};
ok( $returned eq '0', 'match improper ref check') or diag('match accepted a ref other than Net::Connection');
# Create a connection with a matching pid and see if it matches
my $conn=Net::Connection->new( $connection_args );
$returned=0;
eval{
$returned=$checker->match( $conn );
};
ok( $returned eq '1', 'pid match check') or diag('Failed to match a matching good pid');
# Create a connection with a matching pid greater than 1000 protocol and make sure it does not match
$connection_args->{pid}='1001';
$conn=Net::Connection->new( $connection_args );
$returned=0;
eval{
$returned=$checker->match( $conn );
};
ok( $returned eq '1', 'pid match check 2') or diag('Failed to match a good pid');
# Create a connection with a matching pid greater than 1000 protocol and make sure it does not match
$connection_args->{pid}='900';
$conn=Net::Connection->new( $connection_args );
$returned=1;
eval{
$returned=$checker->match( $conn );
};
ok( $returned eq '0', 'pid non-match check') or diag('Matched a pid that it should not of');
done_testing(8);