如何在Windows 7中查询netstat以查找特定本地地址的PID? [英] How to query netstat to find PID for specific local address in Windows 7?
问题描述
我经常在本地地址[::]:8080
上启动服务器.要终止服务器,我需要从netstat -aon
获取的PID
.
I frequently start server on local address [::]:8080
. To terminate server I need PID
fetched from netstat -aon
.
要终止此服务器,请执行taskkill /F /PID <found pid>
To terminate this server I do taskkill /F /PID <found pid>
我想创建可以找到PID的Windows批处理文件并将其应用于调用taskkill /F /PID <found pid>
I want to create windows batch file that can find PID and apply it in call taskkill /F /PID <found pid>
如何创建此类批处理文件?
How can I create such batch file?
谢谢!
推荐答案
在我的PC上可能存在UDP或TCP连接,并且它们需要略有不同的代码:
测试此命令以查看taskkill命令之一是否正确,然后删除echo
以启用taskkill命令.
On my PC there could be a UDP or TCP connection and they require slightly different code:
Test this to see if one of the taskkill commands looks right and remove echo
to enable the taskkill command.
@echo off
for /f "tokens=5" %%a in ('netstat -aon ^|find " [::]:8080 " ^|find /i " TCP " ') do echo taskkill /F /PID %%a
for /f "tokens=4" %%a in ('netstat -aon ^|find " [::]:8080 " ^|find /i " UDP " ') do echo taskkill /F /PID %%a
这篇关于如何在Windows 7中查询netstat以查找特定本地地址的PID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!