#!/usr/bin/perl #< ....o.... ask@unixmonks.net ....o.... ># open(PRTCP,'/proc/net/tcp');while(<PRTCP>){ chomp;next if/^\s*$/;s/^\s*//;s/\s*$//;next if/^sl/;split/\s+/;@p=split':',$_[1];$h{hex $p[1]}=$_[7];}foreach(sort{$a<=>$b}keys%h){ print$_,"\t",[getpwuid($h{$_})]->[0],"\n"};

Replies are listed 'Best First'.
Re: List open TCP ports in linux
by clintp (Curate) on Jan 10, 2001 at 21:16 UTC
    If you're going to tighten, tighten!

    #!/usr/bin/perl #< ....o.... ask@unixmonks.net ....o.... ># @ARGV=q(/proc/net/tcp);while(<>){s/(^\s*|\s *$)//sx;next if/^$/ or /sl/;split/\s+|:/x; $h{hex$_[3]}=$_[12]}for(sort{$a<=>$b}keys%h ){print"$_\t@{[[getpwuid($h{$_})]->[0]]}\n"}