2

如何在 Mac OS X 上查看哪个进程正在侦听端口 8001?

我尝试了几个命令:

lsof -i | grep LISTEN
qbittorre   321 user   26u  IPv4 0xc8e6037f28270c31      0t0  TCP *:6881 (LISTEN)
qbittorre   321 user   27u  IPv6 0xc8e6037f216348e1      0t0  TCP *:6881 (LISTEN)
mysqld    14131 user   10u  IPv4 0xc8e6037f3218da91      0t0  TCP *:mysql (LISTEN)
httpd     14133 user   16u  IPv6 0xc8e6037f216352e1      0t0  TCP *:http (LISTEN)
httpd     14135 user   16u  IPv6 0xc8e6037f216352e1      0t0  TCP *:http (LISTEN)
httpd     14136 user   16u  IPv6 0xc8e6037f216352e1      0t0  TCP *:http (LISTEN)
httpd     14137 user   16u  IPv6 0xc8e6037f216352e1      0t0  TCP *:http (LISTEN)
httpd     14138 user   16u  IPv6 0xc8e6037f216352e1      0t0  TCP *:http (LISTEN)
httpd     14139 user   16u  IPv6 0xc8e6037f216352e1      0t0  TCP *:http (LISTEN)
httpd     14148 user   16u  IPv6 0xc8e6037f216352e1      0t0  TCP *:http (LISTEN)
httpd     14149 user   16u  IPv6 0xc8e6037f216352e1      0t0  TCP *:http (LISTEN)
httpd     14150 user   16u  IPv6 0xc8e6037f216352e1      0t0  TCP *:http (LISTEN)
Skype     14543 user   57u  IPv4 0xc8e6037f324f9a91      0t0  TCP *:18666 (LISTEN)
java      24640 user   68u  IPv6 0xc8e6037f3295a3e1      0t0  TCP *:http-alt (LISTEN)
java      24640 user   73u  IPv6 0xc8e6037f32958fe1      0t0  TCP *:8009 (LISTEN)
java      24640 user  101u  IPv6 0xc8e6037f32959ee1      0t0  TCP localhost:8005 (LISTEN)

lsof:

sudo lsof -nPi -sTCP:LISTEN | grep 8001

什么都没找到

网络统计:

网络统计-a | grep 8001

什么都没找到

我知道该端口正在被某人使用,因为我试图将 Emacs simple-httpd 默认 httpd-port 从 8080(默认)更改为 8001,但它失败了:

Warning (initialization): An error occurred while loading `/Users/user/.emacs':

File error: Cannot bind server socket, address already in use

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.

我该如何解决?我还尝试将端口设置为 8002,但遇到了同样的问题,但没有找到正在侦听端口 8002 的进程。

问题的根源是什么?

编辑:使用nmap我发现端口 8001 被vcom-tunnel服务使用,它是一个封闭的端口,端口 8002 被teradataordbms使用并且也被关闭。

这些服务是做什么用的?我可以禁用它们并使用它们占用的端口吗?

4

1 回答 1

1

这不是答案,我只是重新表述这个问题:

  • 在给定端口上设置服务器失败并出现错误Address already in use
  • lsof不报告该端口的任何侦听器

这是演示这一点的 shell 日志:

[1]$ python -m SimpleHTTPServer 3333 2>&1 | fgrep error
socket.error: [Errno 48] Address already in use
[2]$ sudo lsof -i TCP:3333
[3]$ echo $?
1

[1]: 在端口上启动 Web 服务器3333失败并出现错误Address already in use

[2]:lsof不报告3333任何人使用的端口

让我们生成流量以强制lsof检测端口的使用情况:在另一个终端打开一个telnet连接:

[1]$ telnet localhost 3333

现在回到你以前的终端,你会看到lsof找到你的端口:

[4]$ sudo lsof -n -P -i :3333
COMMAND   PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
telnet  78142 loic    5u  IPv4 0x3fa2e8474ece6129      0t0  TCP 127.0.0.1:51855->127.0.0.1:3333 (ESTABLISHED)

有流量在进行,但是根据操作系统,只有一个连接的一端,发起者,仍然没有LISTENER

注意:在我的情况下,操作系统是 macOS 10.13.3,但我在以前版本的 macOS/OSX 上也有这种情况

于 2018-03-01T13:54:00.170 回答