I want to make a script, that will
- Determine which ports are running.
- Kill the process running on the port, will take a port number as an argument.
I completed the first task, but the 2nd task has some problems. This thread suggests that lsof
is not cross-platform making this problem somewhat impossible to solve.
I then tried using netstat -b
from python to list ut PIDs but it requires privileges, which am not sure how to do that by using the subprocess
module.
tcpview
and tcpvcon
arent helpful either. Using tcpvcon -a 443
for some reason returns nothing.
I am not sure if psutil
module can help either, I know how to find a PID using it, but not sure how to find PIDs according to a specific port.
Is there any cross-platfrom way to do that? Maybe call a Bash script from python?