How do I "Close Connection" like TCPView does, using the command line? [closed]

Solution 1:

http://nirsoft.net/utils/cports.html - see "Closing a connection from Command-line" section (I've not tried it).

Solution 2:

You could use hping3 to send a tcp reset from the same source port to the same destination ip/port as the connection you'd like to close. netstat -b will give you the process information.

Solution 3:

Tcpkill from dsniff performs a bruteforce on the tcp sequence to send RST to the target flow. Use it with lsof or netstat to get the open sockets, then kill them :

petrus@seth:~$ sudo lsof -i TCP:80
COMMAND    PID   USER TYPE NODE NAME
chromium- 2674 petrus IPv4 TCP  seth:44545->stackoverflow.com:www  (ESTABLISHED)

petrus@seth:~$ sudo tcpkill -9 port 44545
tcpkill: listening on eth0 [port 44545]
64.34.119.12:80 > 172.22.151.34:44545: R 2186116153:2186116153(0) win 0
64.34.119.12:80 > 172.22.151.34:44545: R 2186116230:2186116230(0) win 0
64.34.119.12:80 > 172.22.151.34:44545: R 2186116384:2186116384(0) win 0
64.34.119.12:80 > 172.22.151.34:44545: R 2186116615:2186116615(0) win 0