From owner-freebsd-net Tue Sep 8 07:20:13 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id HAA07432 for freebsd-net-outgoing; Tue, 8 Sep 1998 07:20:13 -0700 (PDT) (envelope-from owner-freebsd-net@FreeBSD.ORG) Received: from ifi.uio.no (ifi.uio.no [129.240.64.2]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id HAA07354 for ; Tue, 8 Sep 1998 07:20:06 -0700 (PDT) (envelope-from dag-erli@ifi.uio.no) Received: from hrotti.ifi.uio.no (2602@hrotti.ifi.uio.no [129.240.64.15]) by ifi.uio.no (8.8.8/8.8.7/ifi0.2) with ESMTP id QAA04941; Tue, 8 Sep 1998 16:17:39 +0200 (MET DST) Received: (from dag-erli@localhost) by hrotti.ifi.uio.no ; Tue, 8 Sep 1998 16:17:39 +0200 (MET DST) Mime-Version: 1.0 To: "Jan B. Koum " Cc: Graeme Brown , "FreeBSD-Net (FreeBSD.Org) List" Subject: Re: How to find which application is using a given UDP port References: Organization: University of Oslo, Department of Informatics X-url: http://www.stud.ifi.uio.no/~dag-erli/ X-other-addresses: 'finger dag-erli@ifi.uio.no' for a list X-disclaimer-1: The views expressed in this article are mine alone, and do X-disclaimer-2: not necessarily coincide with those of any organisation or X-disclaimer-3: company with which I am or have been affiliated. X-Stop-Spam: http://www.cauce.org/ From: dag-erli@ifi.uio.no (Dag-Erling Coidan =?iso-8859-1?Q?Sm=F8rgrav?= ) Date: 08 Sep 1998 16:17:37 +0200 In-Reply-To: dag-erli@ifi.uio.no's message of "07 Sep 1998 12:13:05 +0200" Message-ID: Lines: 48 X-Mailer: Gnus v5.5/Emacs 19.34 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by hub.freebsd.org id HAA07410 Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org 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 () { @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 () { @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