how to map listening network ports to processes on freebsd

on linux, one can do netstat -pantup to display listening ports and their associated processes. the netstat(1) command on freebsd doesn’t have the -p option. however, one may obtain the same information using sockstat(1). unlike linux netstat, the sockstat command doesn’t require root privileges.

idox ~ $ sockstat -P tcp,udp -l | tr -s ' ' | cut -f2,6 -d' ' | sort -u
COMMAND LOCAL
Xorg *:6000
Xvnc *:5801
Xvnc *:5901
Xvnc *:6001
dictd *:2628
musicpd *:6600
musicpd *:7000
ntpd *:123
ntpd 127.0.0.1:123
ntpd 192.168.0.20:123
ntpd ::1:123
ntpd fe80::1%lo0:123
rpcbind *:*
rpcbind *:111
rpcbind *:650
rpcbind *:788
smtpd 127.0.0.1:25
smtpd ::1:25
smtpd fe80::1%lo0:25
sshd *:2222
synergys *:24800
syslogd *:514

that’s all folks!
…dave
Sun Nov 12 17:52:29 PST 2017