Batch - Network Scanner with Status Indicator


By: Newbie10
April 22, 2013

I created this batch file because I needed a quick way to see what ip addresses were available on my home network in order to assign static ip addresses. I think this could be very useful to others! Let me know what you think or if I can improve it in any way!!

START OF CODE:

@echo off

:Intro
echo.
echo Network Scanner
echo -----------------
echo.
echo This batch file scans the IP address range with a timeout of 160ms
echo.
echo.
echo Please enter the first three sets of the ip address in this format:
set /p ipbegin=Example: "192.168.1" :


if exist errorchk.bat del errorchk.bat
if exist "%userprofile%\desktop\IP Scan.txt" del "%userprofile%\desktop\IP Scan.txt"
if exist "%userprofile%\desktop\Domain Scan.txt" del "%userprofile%\desktop\Domain Scan.txt"

 

::Create errorchk.bat
echo @echo off>>errorchk.bat
echo echo.>>errorchk.bat
echo echo Error level finder>>errorchk.bat
echo rem run program>>errorchk.bat
echo call %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>>errorchk.bat
echo. >>errorchk.bat
echo for /l %%%%f in (255, -1, 0) do (>>errorchk.bat
echo if errorlevel=%%%%f echo Errorlevel=%%%%f>>errorchk.bat
echo )>>errorchk.bat


set errorlevel=0


rem Declare variables
set timeout=0

if "%1"=="" (
echo Default timeout used [160 ms]
set timeout=160
echo.
)

:settimeout
if %timeout%==0 set timeout=%1


:default
for /l %%f in (1, 1, 254) do (
set errorlevel=0

call "errorchk.bat" ping -n 1 -w %timeout% %ipbegin%.%%f  > nul

rem log entry
if not errorlevel=1 echo %ipbegin%.%%f active>>"%userprofile%\desktop\IP Scan.txt"
if errorlevel=1 echo %ipbegin%.%%f inactive>>"%userprofile%\desktop\IP Scan.txt"

if %%f EQU 1 (cls
echo.
echo [                             ]    0 Percent Complete)
if %%f EQU 25 (cls
echo.
echo [###                          ]    10 Percent Complete)
if %%f EQU 55 (cls
echo.
echo [######                       ]    20 Percent Complete)
if %%f EQU 75 (cls
echo.
echo [#########                    ]    30 Percent Complete)
if %%f EQU 100 (cls
echo.
echo [############                 ]    40 Percent Complete)
if %%f EQU 125 (cls
echo.
echo [###############              ]    50 Percent Complete)
if %%f EQU 150 (cls
echo.
echo [##################           ]    60 Percent Complete)
if %%f EQU 175 (cls
echo.
echo [#####################        ]    70 Percent Complete)
if %%f EQU 200 (cls
echo.
echo [########################     ]    80 Percent Complete)
if %%f EQU 225 (cls
echo.
echo [###########################  ]    90 Percent Complete)
if %%f EQU 254 (cls
echo.
echo [#############################]    Network Scan complete)
)

if exist errorchk.bat del errorchk.bat

echo.
echo.
echo.
echo.
echo If you would like to get a list of all machines on your
echo.
echo current domain, please type 'y' and hit enter.
echo.
echo.
echo Otherwise, press any key to exit...
set /p yes= :
if %yes%==y (
goto domainscan
set errorlevel=0
goto end
)


:domainscan
:: Scans Network and returns Active Computer Names
net view /all >> "%userprofile%\desktop\Domain Scan.txt"

echo.
echo.
echo.
echo [#############################]    Domain Scan completed
echo.
echo.
echo.
echo Please reivew the logs placed on your desktop
echo.
echo Press any key to exit
pause >nul


:end
exit


Need more help?
Describe your Problem
Example: Hard Drive Not Detected on My PC

Ask Question