killport bat腳本 強制殺死占用端口的進程

https://blog.csdn.net/PiaoMiaoXiaodao/article/details/89792789

@echo off
rem open var delay
setlocal enabledelayedexpansion
rem recev var
set port=%1%
if "%port%" == "" (
echo Please enter port
goto end
)
echo ---------------start find who is using port %port%-----------------------
rem Add colon before port and space after port to ensure no mistake
for /f "tokens=1-5" %%a in ('netstat -ano ^| find ":%port% "') do (
rem a is protocol,b is local ip:port, c is remote ip:port,d is state or pid,e is pid or null
echo %%a %%b %%c %%d %%e
rem Cut the %%b with the : to get the port
for /f "delims=:, tokens=1-2" %%j in ("%%b") do (set destport=%%k)
rem Delay variable in for loop must use! Symbol instead of% symbol
echo The port found here is !destport!. What we need is %port%
rem If %%b cuts the same port as the target port
if "!destport!" equ "%port%" (
if "%%e" == "" (
rem sometimes e is empty pid in d
if not "%%d" == "0" (
echo get d col pid %%d
set pid=%%d
)
) else (
if not "%%e" == "0" (
echo get e col pid %%e
set pid=%%e
)
)
) else (
echo this row local not use port %port%
)
)
echo ---------------end find who is using port %port%-----------------------
if "%pid%"=="" (
echo Port %port% is not in use
) else (
echo used port %port% the process %pid%
taskkill /f /pid %pid%
)

:end
echo ---------------end----------------------------------------------------

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • .bat腳本基本命令語法 目錄 批處理的常見命令(未列舉的命令還比較多,請查閱幫助信息) 1、REM 和 :: 2...
    慶慶慶慶慶閱讀 8,529評論 1 19
  • 一、基礎(chǔ)語法: 1.批處理文件是一個“.bat”結(jié)尾的文本文件,這個文件的每一行都是一條DOS命令??梢允褂萌魏挝?..
    蔣_Sir閱讀 9,379評論 1 4
  • Windows CMD命令大全 命令簡介 cmd是command的縮寫.即命令行 。 雖然隨著計算機產(chǎn)業(yè)的發(fā)展,W...
    獨行小生閱讀 702評論 0 5
  • 完全沒想到這篇文章的閱讀量有點多,之前沒有考慮什么就直接發(fā)布了,對此表示歉意,所以重新找了一篇文章匯總,以免在坑到...
    BabyFatXu閱讀 1,812評論 0 1
  • win7 cmd管理員權(quán)限設(shè)置 net localgroup administrators 用戶名 /add 把“...
    f675b1a02698閱讀 5,502評論 0 11

友情鏈接更多精彩內(nèi)容