【问题标题】:Can't find which process is listening on port 8001 on Mac OS X在 Mac OS X 上找不到哪个进程正在侦听端口 8001
【发布时间】:2015-01-31 20:55:21
【问题描述】:

如何在 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

没有找到

网络统计:

netstat -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 并且也关闭了。

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

【问题讨论】:

  • 另见this question
  • 我试过sudo lsof -n -i4TCP:8001 | grep LISTEN 但没有。好像没有使用8001端口,但我不明白为什么我一直收到emacs simple-httpd错误...
  • 请检查我的编辑!
  • 感谢您的链接!无论如何,自从我上次发表评论以来,我已经解决了,只是没有更新。 lsof -i:portnumber 工作。

标签: macos emacs port netstat lsof


【解决方案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] : 在端口 3333 上启动 Web 服务器失败并出现错误 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 上也有这种情况

【讨论】:

    猜你喜欢
    • 2010-09-08
    • 2014-06-12
    • 2010-09-08
    • 2015-03-18
    • 2011-05-24
    • 1970-01-01
    • 2012-08-12
    相关资源
    最近更新 更多