now works again, add --dump, and now uses sockstat on FreeBSD
This commit is contained in:
parent
5d7b6abc87
commit
703cd7c497
|
@ -13,6 +13,7 @@ sub help{
|
|||
print '
|
||||
-a Show all connections.
|
||||
--drp Do not resolve port names.
|
||||
--dump Show the Net::Connection::Match filter and exit.
|
||||
-i Invert the sort.
|
||||
-l Show the listening ports.
|
||||
-n Do not resolve the PTRs.
|
||||
|
@ -154,6 +155,7 @@ my $cpu_string;
|
|||
my $cpu_invert=0;
|
||||
my $mem_string;
|
||||
my $mem_invert=0;
|
||||
my $dump=0;
|
||||
|
||||
# get the commandline options
|
||||
Getopt::Long::Configure ('no_ignore_case');
|
||||
|
@ -214,6 +216,7 @@ GetOptions(
|
|||
'cpui' => \$cpu_invert,
|
||||
'mem=s' => \$mem_string,
|
||||
'memi' => \$mem_invert,
|
||||
'dump' => \$dump,
|
||||
);
|
||||
|
||||
my @filters;
|
||||
|
@ -236,22 +239,23 @@ if (
|
|||
( ! $listening )
|
||||
){
|
||||
# If -a is not given, we don't want the listen ports
|
||||
push( @filters, {
|
||||
push( @filters,
|
||||
{
|
||||
type=>'Ports',
|
||||
invert=>1,
|
||||
args=>{
|
||||
ports=>[
|
||||
'*',
|
||||
],
|
||||
}
|
||||
},
|
||||
{
|
||||
type=>'States',
|
||||
invert=>1,
|
||||
args=>{
|
||||
states=>['LISTEN']
|
||||
}
|
||||
},
|
||||
{
|
||||
type=>'Ports',
|
||||
invert=>1,
|
||||
args=>{
|
||||
fports=>[
|
||||
'*',
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}elsif(
|
||||
$listening &&
|
||||
|
@ -608,6 +612,13 @@ if ( $command_long && ! $command ){
|
|||
$command=1;
|
||||
}
|
||||
|
||||
#dump the filters if asked
|
||||
if ($dump) {
|
||||
use Data::Dumper;
|
||||
print Dumper( \@filters );
|
||||
exit;
|
||||
}
|
||||
|
||||
my $ncnetstat=Net::Connection::ncnetstat->new(
|
||||
{
|
||||
ptr=>$ptr,
|
||||
|
|
|
@ -11,6 +11,14 @@ use Term::ANSIColor;
|
|||
use Proc::ProcessTable;
|
||||
use Text::ANSITable;
|
||||
|
||||
# use Net::Connection::FreeBSD_sockstat if possible
|
||||
if ( $^O =~ /freebsd/ ) {
|
||||
use Net::Connection::FreeBSD_sockstat;
|
||||
}else {
|
||||
use Net::Connection::lsof;
|
||||
}
|
||||
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
@ -168,8 +176,14 @@ This runs it and returns a string.
|
|||
|
||||
sub run{
|
||||
my $self=$_[0];
|
||||
|
||||
my @objects = &lsof_to_nc_objects;
|
||||
|
||||
my @objects;
|
||||
if ( $^O !~ /freebsd/ ) {
|
||||
@objects = &lsof_to_nc_objects;
|
||||
}
|
||||
else {
|
||||
@objects = &sockstat_to_nc_objects;
|
||||
}
|
||||
|
||||
my @found;
|
||||
if (defined( $self->{match} )){
|
||||
|
@ -185,8 +199,8 @@ sub run{
|
|||
@found=$self->{sorter}->sorter( \@found );
|
||||
|
||||
my $tb = Text::ANSITable->new;
|
||||
$tb->border_style('Default::none_ascii'); # if not, a nice default is picked
|
||||
$tb->color_theme('Default::no_color'); # if not, a nice default is picked
|
||||
$tb->border_style('ASCII::None');
|
||||
$tb->color_theme('NoColor');
|
||||
|
||||
my @headers;
|
||||
my $header_int=0;
|
||||
|
@ -204,7 +218,7 @@ sub run{
|
|||
$tb->set_column_style($header_int, pad => 0); $header_int++;
|
||||
push( @headers, 'Remote Host' );
|
||||
$tb->set_column_style($header_int, pad => 1, formats=>[[wrap => {ansi=>1, mb=>1}]]); $header_int++;
|
||||
push( @headers, 'Prt' );
|
||||
push( @headers, 'Port' );
|
||||
$tb->set_column_style($header_int, pad => 0); $header_int++;
|
||||
push( @headers, 'State' );
|
||||
$tb->set_column_style($header_int, pad => 1); $header_int++;
|
||||
|
|
Loading…
Reference in New Issue