@echo off&color a&Title CM07-Task
chcp 65001
setlocal enabledelayedexpansion&echo.&echo.
for /L %%k in (1 1 60) do set /p gu=*<nul
echo.&echo * 端口-进程查询(查看进程使用的端口) *
echo * Levi *
for /L %%k in (1 1 60) do set /p gu=*<nul
echo.&echo.&echo.&echo 端口号 进程名称
ECHO TCP协议:
for /F "usebackq skip=4 tokens=2,5" %%i in (`"netstat -ano -p TCP"`) do (
call :Assoc %%i TCP %%j
echo !TCP_Port! !TCP_Proc_Name!
)
ECHO UDP协议:
for /F "usebackq skip=4 tokens=2,4" %%i in (`"netstat -ano -p UDP"`) do (
call :Assoc %%i UDP %%j
echo !UDP_Port! !UDP_Proc_Name!
)
echo 请按任意键退出本程序。
pause>nul
:Assoc
for /F "tokens=2 delims=:" %%e in ("%1") do (
set %2_Port=%%e
)
for /F "skip=2 usebackq delims=, tokens=1" %%a in (`"Tasklist /FI "PID eq %3" /FO CSV"`) do (
set %2_Proc_Name=%%~a
)
goto :eof