Hey guys,
I wrote the following batch script to use along with portqry tool which is availabe from microsoft download center.
The tool can scan multiple ports on a single computer, but it is not capable of scanning multiple ports on multiple computers in one attempt. Also it gives a big output which is a bit tough if you are trying to prepare a report.
Here is the batch file which takes input from server.txt where all the computer names present and scans for the below ports on each computer and gives you output in a beautiful way.
TCP: 135, 445, 1433, 1434, 1024, 1040
UDP: 1433, 1434
Copy and paste the below code in a batch file and use it along with portqry.exe.
************************************************************************************************************************
echo off
for /f "tokens=* delims= " %%a in (server.txt) do call :vk %%a
:vk
portqry -n %1 -e 1434 -q -p udp
if errorlevel = 2 goto filtered_1434
if errorlevel = 1 goto failed_1434
if errorlevel = 0 goto success_1434
goto 135
:filtered_1434
Echo %1 udp Port 1434 is listening or filtered
goto 135
:failed_1434
Echo %1 udp Port 1434 is not listening
Goto 135
:success_1434
Echo %1 udp Port 1434 is listening
goto 135
:135
portqry -n %1 -e 135 -q -p tcp
if errorlevel = 2 goto filtered_135
if errorlevel = 1 goto failed_135
if errorlevel = 0 goto success_135
goto 445
:filtered_135
Echo %1 tcp Port 135 is listening or filtered
goto 445
:failed_135
Echo %1 tcp Port 135 is not listening
Goto 445
:success_135
Echo %1 tcp Port 135 is listening
goto 445
:445
portqry -n %1 -e 445 -q -p tcp
if errorlevel = 2 goto filtered_445
if errorlevel = 1 goto failed_445
if errorlevel = 0 goto success_445
goto 1433_tcp
:filtered_445
Echo %1 tcp Port 445 is listening or filtered
goto 1433_tcp
:failed_445
Echo %1 tcp Port 445 is not listening
Goto 1433_tcp
:success_445
Echo %1 tcp Port 445 is listening
goto 1433_tcp
:1433_tcp
portqry -n %1 -e 1433 -q -p tcp
if errorlevel = 2 goto filtered_1433_tcp
if errorlevel = 1 goto failed_1433_tcp
if errorlevel = 0 goto success_1433_tcp
goto 1434_tcp
:filtered_1433_tcp
Echo %1 tcp Port 1433 is listening or filtered
goto 1434_tcp
:failed_1433_tcp
Echo %1 tcp Port 1433 is not listening
Goto 1434_tcp
:success_1433_tcp
Echo %1 tcp Port 1433 is listening
goto 1434_tcp
:1434_tcp
portqry -n %1 -e 1434 -q -p tcp
if errorlevel = 2 goto filtered_1434_tcp
if errorlevel = 1 goto failed_1434_tcp
if errorlevel = 0 goto success_1434_tcp
goto 1024
:filtered_1434_tcp
Echo %1 tcp Port 1434 is listening or filtered
goto 1024
:failed_1434_tcp
Echo %1 tcp Port 1434 is not listening
Goto 1024
:success_1434_tcp
Echo %1 tcp Port 1434 is listening
goto 1024
:1024
portqry -n %1 -e 1024 -q -p tcp
if errorlevel = 2 goto filtered_1024
if errorlevel = 1 goto failed_1024
if errorlevel = 0 goto success_1024
goto 1040
:filtered_1024
Echo %1 tcp Port 1024 is listening or filtered
goto 1040
:failed_1024
Echo %1 tcp Port 1024 is not listening
Goto 1040
:success_1024
Echo %1 tcp Port 1024 is listening
goto 1040
:1040
portqry -n %1 -e 1040 -q -p tcp
if errorlevel = 2 goto filtered_1040
if errorlevel = 1 goto failed_1040
if errorlevel = 0 goto success_1040
goto 1433
:filtered_1040
Echo %1 tcp Port 1040 is listening or filtered
goto 1433
:failed_1040
Echo %1 tcp Port 1040 is not listening
Goto 1433
:success_1040
Echo %1 tcp Port 1040 is listening
goto 1433
:1433
portqry -n %1 -e 1433 -q -p udp
if errorlevel = 2 goto filtered_1433
if errorlevel = 1 goto failed_1433
if errorlevel = 0 goto success_1433
goto end
:filtered_1433
Echo %1 udp Port 1433 is listening or filtered
goto end
:failed_1433
Echo %1 udp Port 1433 is not listening
Goto end
:success_1433
Echo %1 udp Port 1433 is listening
goto end
:End