有人知道如何通过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).


当前回答

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

TASKKILL /f /pid 1234 

我希望这对你有用

其他回答

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

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

为了关闭该端口,您可以确定正在侦听该端口的进程并杀死该进程。

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

TASKKILL /f /pid 1234 

我希望这对你有用

Wkillcx是一个可靠的Windows命令行工具,用于从前面没有提到的命令行删除TCP连接。不过,它有时确实会在连接大量的服务器上出现问题。我有时使用tcpview进行交互式kill,但wkillcx可以在脚本中使用。