2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MacOSX でTCP LISTENしているプロセスとポート番号を知るには

Last updated at Posted at 2015-06-23

実現したいこと

$ sudo netstat -ntpl

Linuxで上記のようにnetstatコマンドを利用して実現していることをMacOSX Mavericksでも実現する

MacOSX Mavericksでnetstatコマンドを利用してListenしているポートを調べるには、-l ではなく -L を利用する。

lsofコマンドを利用する

$ sudo lsof -nP -iTCP | grep LISTEN
  • MacOSX Mavericksに標準で導入されているnetstatコマンドは、Linuxに標準で導入されているnetstatコマンドとは、若干仕様が違うため lsofコマンドを利用します。
$ netstat -h
netstat: illegal option -- h
Usage:	netstat [-AaLlnW] [-f address_family | -p protocol]
	netstat [-gilns] [-f address_family]
	netstat -i | -I interface [-w wait] [-abdgRt]
	netstat -s [-s] [-f address_family | -p protocol] [-w wait]
	netstat -i | -I interface -s [-f address_family | -p protocol]
	netstat -m [-m]
	netstat -r [-Aaln] [-f address_family]
	netstat -rs [-s]

$
$ man netstat

〜 snip 〜

     -L    Show the size of the various listen queues.  The first count shows the number of unaccepted connections.  The second count shows the amount of unaccepted incomplete con-
           nections.  The third count is the maximum number of queued connections.

     -l    Print full IPv6 address.

〜 snip 〜
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?