Date: 08 Sep 1998 16:17:37 +0200 From: dag-erli@ifi.uio.no (Dag-Erling Coidan =?iso-8859-1?Q?Sm=F8rgrav?= ) To: "Jan B. Koum " <jkb@best.com> Cc: Graeme Brown <graeme.brown@bt-sys.bt.co.uk>, "FreeBSD-Net (FreeBSD.Org) List" <freebsd-net@FreeBSD.ORG> Subject: Re: How to find which application is using a given UDP port Message-ID: <xzpzpca4rjy.fsf@hrotti.ifi.uio.no> In-Reply-To: dag-erli@ifi.uio.no's message of "07 Sep 1998 12:13:05 %2B0200" References: <Pine.BSF.4.02A.9809070222480.6323-100000@shell6.ba.best.com> <xzppvd8ut72.fsf@hrotti.ifi.uio.no>
next in thread | previous in thread | raw e-mail | index | archive | help
dag-erli@ifi.uio.no (Dag-Erling Coidan Smørgrav ) writes: > It should be relatively easy to write a Perl script that combines the > output of each command and prints something like this: Here it is: #!/usr/local/bin/perl5 format STDOUT_TOP = USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS . format STDOUT = @<<<<<<< @<<<<<<<<< @>>>> @>>>> @<< @<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<< $user, $process, $pid, $fd, $p, $local_addr, $foreign_addr . open NETSTAT, "netstat -Aan |" or die "netstat -Aan failed"; while (<NETSTAT>) { @a = split; next unless (($a[1] eq "tcp") or ($a[1] eq "udp")); $myaddr{$a[0]} = $a[4]; $hisaddr{$a[0]} = $a[5]; } close NETSTAT; open FSTAT, "fstat |" or die "fstat failed"; while (<FSTAT>) { @a = split; next unless ($a[4] eq "internet"); $user = $a[0]; $process = $a[1]; $pid = $a[2]; $fd = $a[3]; $fd =~ s/\*$//; $p = $a[6]; $socket = $a[7]; $local_addr = $myaddr{$socket}; $foreign_addr = $hisaddr{$socket}; write STDOUT; } close FSTAT; DES -- Dag-Erling Smørgrav - dag-erli@ifi.uio.no To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpzpca4rjy.fsf>