more resolver work, making it optional

This commit is contained in:
Zane C. B-H 2019-03-03 03:40:35 -06:00
parent 69555c454f
commit c802e4cbd0
4 changed files with 84 additions and 6 deletions

View File

@ -1,6 +1,6 @@
Revision history for Parse-Netstat-Colorizer
0.1.0 2019-03-03/02:55
0.1.0 2019-03-03/03:00
-Add inversion support to cnetstat.
-Add PTR and regexp PTR support to cnetstat.
-Add PTR resolving options.

View File

@ -23,10 +23,10 @@ WriteMakefile(
'Error::Helper'=>'1.0.0',
'Parse::Netstat::Search'=>'0.1.1',
'Parse::Netstat::Search::Sort'=>'0.0.0',
'Term::ANSIColor'=>'0.0.0',
'Text::Table'=>'0.0.0',
'Term::ANSIColor'=>'4.06',
'Text::Table'=>'1.133',
'Getopt::Long'=>'0.0.0',
'Net::IP'=>'0.0.0',
'Net::DNS'=>'1.19',
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Parse-Netstat-Colorizer-*' },

View File

@ -23,7 +23,7 @@ sub help{
-i Invert the sort.
-l Equivalent of "-a -s listen". Can be combined with -s.
--nc Don\'t colorize the output.
-p <poorts> A comma seperated list of ports to search for.
-p <ports> A comma seperated list of ports to search for.
--pi Invert the port search.
-P <protocols> A comma seperated list of protocols to search for.
--Pi invert the protocol search.
@ -60,6 +60,7 @@ my $cidr_invert;
my $states_invert;
my $protocols_invert;
my $no_color=0;
my $no_use_ptr=0;
#set the default sort via ENV if requested
if ( defined( $ENV{CNETSTAT_sort} ) ){
@ -94,6 +95,7 @@ GetOptions(
'rptr=s' => \$rptrs_string,
'rptri' => \$rptrs_invert,
'nc' => \$no_color,
'n' => \$no_use_ptr,
);
# print version or help if requested
@ -110,6 +112,10 @@ if ( $version ){
if ( defined( $ENV{CNETSTAT_invert} ) ){
$invert= $invert ^ $ENV{CNETSTAT_invert};
}
# XOR the -n value if needed
if ( defined( $ENV{CNETSTAT_ptr} ) ){
$no_use_ptr = $no_use_ptr ^ $ENV{CNETSTAT_ptr};
}
# same for the no color
if ( defined( $ENV{NO_COLOR} ) ){
$no_color = $no_color ^ 1;
@ -182,6 +188,11 @@ if ( defined( $invert ) ){
$pnc->set_invert($invert);
}
# invert if requested
if ( $no_use_ptr ){
$pnc->set_ptr_resolve(0);
}
# invert if requested
if ( defined( $no_color ) ){
$pnc->set_no_color($no_color);

View File

@ -9,7 +9,7 @@ use Parse::Netstat::Search;
use Parse::Netstat::Search::Sort;
use Term::ANSIColor;
use Text::Table;
use Net::IP;
use Net::DNS;
=head1 NAME
@ -51,6 +51,9 @@ Sorting and searching is handled via L<Parse::Netsat::Search> and
L<Parse::Netstat::Search::Sort>. Their objects for tweaking can be
fetched via get_sort and get_search.
L<Net::DNS::Resolver> is used for resolving hostnames. For setting
the
=head1 METHODS
=head2 new
@ -299,6 +302,46 @@ sub get_port_resolve{
return $self->{port_resolve};
}
=head2 get_ptr_resolve
This gets the current setting for if it should resolve
IPs to PTRs or not.
The returned value is a boolean and defaults to 1.
my $use_ptr=$pnc->get_ptr_resolve;
=cut
sub get_ptr_resolve{
my $self=$_[0];
if( ! $self->errorblank ){
return undef;
}
return $self->{use_ptr};
}
=head2 get_resolver
This returns the L<Net::DNS::Resolver> object used
for resolving IPs to PTRs.
my $resolver=$pnc->get_resolver;
=cut
sub get_resolver{
my $self=$_[0];
if( ! $self->errorblank ){
return undef;
}
return $self->{resolver};
}
=head1 get_search
This returns the Parse::Netstat::Search object.
@ -411,6 +454,30 @@ sub set_port_resolve{
$self->{port_resolve}=$_[1];
}
=head2 set_ptr_resolve
This sets wether or not it will resolve IPs to PTRs.
One value is taken and that is a perl boolean.
# sets it to true, the default
$pnc->set_ptr_resolve(1);
# set it false, don't resolve the ports
$pnc->set_ptr_resolve;
=cut
sub set_ptr_resolve{
my $self=$_[0];
if( ! $self->errorblank ){
return undef;
}
$self->{use_ptr}=$_[1];
}
=head
=head1 ERROR CODES / FLAGS