有人知道如何通过windows命令行关闭单个连接的TCP或UDP套接字吗?

我在谷歌上搜索了一下,看到一些人也问了同样的问题。但是答案看起来像是netstat或netsh命令的手册页,重点关注如何监视端口。我不想要关于如何监控它们的答案(我已经这样做了)。我想干掉他们。

EDIT, for clarification: Let's say that my server listens TCP port 80. A client makes a connection and port 56789 is allocated for it. Then, I discover that this connection is undesired (e.g. this user is doing bad things, we asked them to stop but the connection didn't get dropped somewhere along the way). Normally, I would add a firewall to do the job, but this would take some time, and I was in an emergency situation. Killing the process that owns the connection is really a bad idea here because this would take down the server (all users would lose functionality when we just want to selectively and temporally drop this one connection).


当前回答

打开cmd 输入netstat -a -n -o 找到TCP [IP地址]:[端口号]....#[target_PID]# (UDP同上) (顺便说一句,杀死[target_PID]没有为我工作) CTRL+ALT+DELETE,选择“启动任务管理器” 单击“进程”选项卡 打开“PID”列,方法如下:查看>选择列>选中“PID”复选框 找到感兴趣的PID和“END PROCESS” 现在您可以在[IP地址]:[端口号]上重新运行服务器,没有任何问题

其他回答

打开cmd 输入netstat -a -n -o 找到TCP [IP地址]:[端口号]....#[target_PID]# (UDP同上) (顺便说一句,杀死[target_PID]没有为我工作) CTRL+ALT+DELETE,选择“启动任务管理器” 单击“进程”选项卡 打开“PID”列,方法如下:查看>选择列>选中“PID”复选框 找到感兴趣的PID和“END PROCESS” 现在您可以在[IP地址]:[端口号]上重新运行服务器,没有任何问题

尝试Sysinternals/Microsoft的工具TCPView (GUI)和Tcpvcon(命令行)。 https://learn.microsoft.com/en-us/sysinternals/downloads/tcpview

是的,有可能关闭TCP或UDP端口,在DOS中有一个命令

TASKKILL /f /pid 1234 

我希望这对你有用

即时/可行/部分答案:https://stackoverflow.com/a/20130959/2584794 与前面使用netstat -a -o -n的答案不同,在没有使用这些端口的应用程序名称的情况下,要查看非常长的列表

如果没有拥有这些套接字,就不能关闭服务器上的套接字,因此如果没有在拥有服务器套接字的进程中运行代码,就不能实际关闭套接字。

然而,还有另一个选项告诉客户端关闭它的套接字。向客户端正在连接的端口发送RST TCP包将导致客户端断开连接。你可以使用nmap进行RST扫描。

http://nmap.org/