I am trying to create a FreePort.cmd script on windows that will kill the process that is running on port 7497 (127.0.0.1:7497).
The windows commands I need to run are:
- netstat -a -o -n
- taskkill /F /IM 912 (912 represents the PID of the process running on 7497)
I know I need to run netstat -a -o -n, loop through it, look up the PID with foreign address column equal to 127.0.0.1:7497, and then terminate the PID. But I am having a lot of trouble creating the *.cmd script.
If this can be done with Python instead of *.cmd that would also be great.