BATCH – Puertos en escucha en el sistema.

@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
Esta entrada fue publicada en BATCH - DOS. Guarda el enlace permanente.

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *