Reputation: 373
Is there any way to see open ports of windows in a specific range using command line?
For example i want to see open ports in range 1-1024.
Upvotes: 0
Views: 1961
Reputation: 4132
This will list all open (in use) ports.
netstat -na
Filtering is a bit harder. This script takes two ports as the (inclusive) range of local ports to filter for.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET STARTPORT=%1
SET ENDPORT=%2
FOR /F "delims=|" %%l IN ('netstat -na') DO (
FOR /F "tokens=2" %%a IN ("%%l") DO (
REM IPv6 uses colons, too.
SET "LOCAL=%%~a"
SET "LOCAL=!LOCAL:*]=0!"
FOR /F "delims=: tokens=2" %%p IN ("!LOCAL!") DO (
IF %%p LEQ %ENDPORT% ( IF %%p GEQ %STARTPORT% ( @ECHO %%l ) )
)
)
)
Upvotes: 3