Skip site navigation (1)Skip section navigation (2)
Date:      07 Sep 1998 12:13:05 +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:  <xzppvd8ut72.fsf@hrotti.ifi.uio.no>
In-Reply-To: "Jan B. Koum "'s message of "Mon, 7 Sep 1998 02:24:10 -0700 (PDT)"
References:  <Pine.BSF.4.02A.9809070222480.6323-100000@shell6.ba.best.com>

next in thread | previous in thread | raw e-mail | index | archive | help
"Jan B. Koum " <jkb@best.com> writes:
> 	Look again:
> 
> % netstat -a
> Active Internet connections (including servers)
> Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
> tcp        0      0  rafraf.1342            shell6.ba.best.c.ssh
> ESTABLISHED
> tcp        0      0  *.6000                 *.*                    LISTEN
> udp        0      0  *.syslog               *.*                   
> ^^^
> 	You can also just "netstat -an | grep udp" :)

It won't tell you *which* app holds the port. fstat(1) will tell you
which processes have open TCP or UDP sockets, but not which port. The
trick is to use 'fstat' and 'netstat -Aan' and compare addresses:

des@fixus-ipv6 ~$ fstat | grep udp
root     xdm          214    1* internet dgram udp f7372d80
daemon   portmap       99    3* internet dgram udp f7372f00
root     xntpd         95    4* internet dgram udp f7372ea0
root     xntpd         95    5* internet dgram udp f7372e40
root     xntpd         95    6* internet dgram udp f7372de0
root     syslogd       85    4* internet dgram udp f7372f60
des@fixus-ipv6 ~$ netstat -Aan | grep udp
f7372d80 udp        0      0  *.177              *.*               
f7372de0 udp        0      0  127.0.0.1.123      *.*               
f7372e40 udp        0      0  128.39.11.50.123   *.*               
f7372ea0 udp        0      0  *.123              *.*               
f7372f00 udp        0      0  *.111              *.*               
f7372f60 udp        0      0  *.514              *.*               

It should be relatively easy to write a Perl script that combines the
output of each command and prints something like this:

root     xdm          214    1* internet dgram udp *.177
daemon   portmap       99    3* internet dgram udp *.111
root     xntpd         95    4* internet dgram udp *.123
root     xntpd         95    5* internet dgram udp 128.39.11.50.123
root     xntpd         95    6* internet dgram udp 127.0.0.1.123
root     syslogd       85    4* internet dgram udp *.514

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?xzppvd8ut72.fsf>