27

On Linux we can kill an Established TCP Connection using tcpkill command.


For example, to drop all connection to/from a particular IP:

tcpkill host ipaddr

Or similary to kill all connection using port 21 at ethernet-1, by:

tcpkill -i eth1 port 21  

Similarly, i want to know what is the command to kill certain connection on windows, precisely windows 7. Like i can see a list of active connections by netstat -n, now i am wondering how to drop a particular or group of connections?

r0ca
  • 5,833
Johnydep
  • 1,155

4 Answers4

34

The Windows Sysinternals Suite contains a tool called TcpView. TcpView will show you all of the connections on your machine similar to netstat. It will also allow you to close the connection or kill the process hosting the connection.

heavyd
  • 65,321
11

The CurrPorts tool from Nirsoft seems to do that. Follow the link and search for 'Closing a Connection From Command-Line'.

1

You can execute netstat -o and the last column shows the process ID tied to the network connection, say, 1234. Then execute tasklist|find "1234" and it'll reveal the process name using that port. You can then choose to execute taskkill /pid 1234 to terminate the running process.

As someone else mentioned, you can simplify all this by using "TcpView" by SysInternals by Microsoft - it is better because it doesn't terminate the application, rather closes the questionable port connection.

-1

CurrPorts (cports.exe) from Nirsoft provides a Windows interface to close the ports or at least to identify the processes that are holding it open. This is a pretty good debugging tool - helped me anyway:

Using CurrPorts

The main window of CurrPorts displays the list of all currently opened TCP and UDP ports. You can select one or more items, and then close the selected connections, copy the ports information to the clipboard, or save it to HTML/XML/Text file. If you don't want to view all available columns, or you want to change the order of the columns on the screen and in the files you save, select 'Choose Column' from the View menu, and select the desired columns and their order. In order to sort the list by specific column, click on the header of the desired column.

http://www.nirsoft.net/utils/cports.html