1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
@echo off setlocal enabledelayedexpansion if exist %temp%\puertos.tmp del %temp%\puertos.tmp >nul tasklist > %temp%\tareas.tmp for /F "usebackq tokens=2,3,4,5,6,7 delims=: " %%g in (`netstat -nao ^| find "LISTENING"`) do ( set sz1=%%h: 0 for /f "tokens=1,2 delims=:" %%s in ("!sz1:~,6!") do set sz1=%%t%%s for /F "usebackq skip=4 tokens=1,2" %%m in (%temp%\tareas.tmp) do if %%l == %%n ( set sz3=%%n: 0 for /f "tokens=1,2 delims=:" %%s in ("!sz3:~,6!") do set sz3=%%t%%s set sz2=%%m: = for /f "tokens=1,2 delims=:" %%s in ("!sz2:~,16!") do set sz2=%%s%%t echo !sz1! !sz2!!sz3! >>%temp%\puertos.tmp ) ) echo. echo Puertos en escucha en el sistema echo. echo Puerto Programa PID echo ------ ------------ ---- set iant= for /F "tokens=1* delims=" %%i in ('SORT %temp%\puertos.tmp') do if %%i NEQ !iant! (echo %%i) & set iant=%%i echo. del %temp%\puertos.tmp >nul del %temp%\tareas.tmp >nul endlocal pause goto :EOF |