#!/usr/local/bin/perl4 # nsox -- list sockets #require 'xloc.pl'; #$netstat = &xloc('netstat') || die "can't find netstat"; #$lsof = &xloc('lsof') || die "can't find lsof"; $netstat = 'netstat'; $lsof = 'lsof'; #rlogin 9480 tchrist 3u inet 0xff64e58c TCP wraeththu:1023->piper:login #telnet 21689 tchrist 3u inet 0xff64dc8c TCP wraeththu:4514->winky.convex.com:telne open(NETSTAT, "$netstat -Aa |") || die "cannot fork $netstat: $!"; while ( ) { ($pcb, $proto, $recv, $send, $local, $foreign, $state) = split; $pcb{$pcb} = $_; } close(NETSTAT) || warn "can't close $netstat: status $?"; open(LSOF, "$lsof -sn |") || die "cannot fork $lsof: $!"; while () { next unless /->/; s/(\.cs)?\.colorado.edu//gi; s/\.convex\.com//gi; s/inet 0x(\S+)//; ($pcb, $proto, $recv, $send, $local, $foreign, $state) = split(' ',$pcb{$1}); ($cmd, $pid, $owner, $fd, $proto, $spec) = split; $state =~ s/([A-Z])[A-Z]+_?/$1/g; $spec =~ s/->/ -> /; $proto =~ tr/A-Z/a-z/; $state =~ tr/A-Z/a-z/; $sr = sprintf("%3d/%-3d", $send, $recv); write; } close(LSOF) || warn "can't close $lsof: status $?"; format STDOUT_TOP = Command Pid User FD Prot ST S/R Where . format STDOUT = @<<<<<<<< @>>>>> @<<<<<<< @>> @<<< @<< @>>/@<< @* $cmd, $pid, $owner,$fd, $proto, $state,$send,$recv, $spec .