如何在macOS上停止\关闭\终止tcp连接



首先,这不是重复的。总的来说,我的问题是:我有另一个应用程序当前正在macOS上运行,我想从终端切断(服务器或关闭或停止(tcp连接。问题是我不想杀死进程,因为这是我在另一个答案中找到的解决方案。+我可以访问sudo并且我知道PID。

我做了什么却不起作用:

lsof -i TCP:X | awk '/LISTEN/ {print $2}' | xargs kill -9

我试图将X更改为从命令中获得的特定值

sudo lsof -i -n -P | grep TCP

放在这里的第二件事https://www.scm.keele.ac.uk/staff/stan/2016/05/16/closing-sockets-without-killing-processes/

但从lldb -p $PID这行,我得到了这样的错误:

error: attach failed: attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries when the attached failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)

也许我错过了什么,也许我应该为我的目的找一个特别的节目?我看到的Windows有一个->https://www.nirsoft.net/utils/cports.html

我真的很好奇,因为我找到的所有答案都建议用户杀死所有进程。但我不想要。

好的。。只需尝试从这里学习代码->https://github.com/doug-leith/appFirewall

谢谢伙计为我提供负反馈。但我的答案是唯一一个在互联网上导致防火墙工作!

最新更新