10

I just want to kill a specific tcp connection on my mac (similar to tcpkill on linux). By port or ip, preferably port but i'll settle. I don't want to pay for a service or download another software, I want the simple terminal command that will allow me to do this like tcpkill.

I've tried fixing up the rules on my firewall, and tried to make a bash script so it would run but to no success because the tutorial I found was very old.

Why does this seem to be such a difficult task to find information on, or do?

7

Option 1

You can install tcpkill. It is part of the dsniff package which is in MacPorts. You said you don't want to install other software. Nevertheless MacPorts is really useful if you work from the command line. I suggest you check it out.

Option 2

On StackOverflow there is a related post: Find (and kill) process locking port 3000 on Mac. The suggested solution there is to create a function that kills all connection on a specific port:

function killport() { lsof -i TCP:$1 | awk '/LISTEN/ {print $2}' | xargs kill -9 }

If you change the function by taking away the argument the function should kill all applications that have an open TCP connection.

function killport() { lsof -i TCP | awk '/LISTEN/ {print $2}' | xargs kill -9 }

Disclaimer: I haven't tested this.

Disclaimer 2: It's a brute force method and can have some serious side effects. I would recommend against this approach.

4
  • I found some OS X binaries for dsniff here (in case you aren't a MacPorts user) here: FWIW packages.macports.org/dsniff (apparently homebrew doesn't have a recipe for it anymore, as of today)
    – rogerdpack
    Jun 17 '15 at 16:59
  • There is a homebrew recipe for it in the homebrew/boneyard tap.
    – D_4_ni
    Sep 23 '15 at 14:10
  • There is a dsniff fork that contains a working tcpkill version: github.com/ggreer/dsniff Jun 19 '19 at 14:54
  • How can I install dsniff using MacPorts? I installed MacPorts, what is the next step? Dec 29 '20 at 12:32
0

FWIW, you have to install openssl@1.0 in order for dsniff to compile successfully.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .