I had a scenario where I wanted to see what was on the network at a location.
So I figured I’d just ping them all, man was this a pain or what! So I wrote a script for it instead. :)
And yes, I know there is alot of IP-scanners out there. But what hacker would I be if I used someone elses programs? I wanted my results in my own custom preferences.
The script was developed further on and now includes hostname lookup and logging to file with identification tags of the current place.
The script will ask all the necessary questions. Its quite useful. Check it out!
@echo off
: Copyright and program name
@set prog=PingTool
@set version=v2.2
@set author=Made by Niklas Jumlin - Copyright 2009-2010
: Set default variables
@for /f "Tokens=1" %%i in ('time /t') do @set tm=%%i
@for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do @set dt=%%i%%j%%k%%l
@set tm=%tm::=.%
@set dtt=%dt% %tm%
@set stop=254
@color 0b
@set requests=2
@set timeout=200
@set trace=n
title %prog% %version%
echo %prog% %version%
echo %author%
: Start asking questions and store in variables
echo.
echo Enter a name for this scan for easier identification, e.g Company Name
@set /p name=Name:
cls
echo %prog% %version%
echo %author%
echo.
echo Your current gateway is listed below:
ipconfig | find /i "gateway"
echo.
echo Set what network segment you would like to scan, e.g 192.168.16
@set /p net=Net (default=none):
cls
echo %prog% %version%
echo %author%
echo.
echo Set IP-range stop
@set /p stop=Stop (default=254):
cls
echo %prog% %version%
echo %author%
echo.
echo Set number of requests sent per IP-number
@set /p requests=Requests (default=2):
cls
echo %prog% %version%
echo %author%
echo.
echo Set timeout (ms) for waiting for response
@set /p timeout=Timeout (default=200):
cls
echo %prog% %version%
echo %author%
echo.
echo Would you also like to lookup hostnames for %net%.1 - %net%.%stop%? (This may take a while)
echo.
@set /p trace=(y/n) (default=n):
if %trace%==y goto full
if %trace%==n goto fast
: Get to work
:fast
cls
echo %prog% %version%
echo %author%
echo %author% >> ipaddresses.txt
echo Scan started at: %dtt% >> ipaddresses.txt
echo Identification: %name% >> ipaddresses.txt
echo Trace=Off >> ipaddresses.txt
echo. >> ipaddresses.txt
echo.
echo Trace=Off
echo.
echo Scan started at: %dtt%
echo Pinging %net%.1 - %net%.%stop%
echo Canceling will result in incomplete results.
echo Results will be saved to ipaddresses.txt where the batch job is located.
echo.
@FOR /L %%t IN (1,1,%stop%) DO title Now pinging: %net%.%%t & echo Now pinging: %net%.%%t & ping -w %timeout% -n %requests% %net%.%%t | find /i "TTL" && echo Found: %net%.%%t >> ipaddresses.txt
goto eof
:full
cls
echo %prog% %version%
echo %author%
echo %author% >> ipaddresses.txt
echo Scan started at: %dtt% >> ipaddresses.txt
echo Identification: %name% >> ipaddresses.txt
echo Trace=On >> ipaddresses.txt
echo. >> ipaddresses.txt
echo.
echo Trace=On
echo.
echo Scan started at: %dtt%
echo Pinging %net%.1 - %net%.%stop%
echo Canceling will result in incomplete results.
echo Results will be saved to ipaddresses.txt where the batch job is located.
echo.
@FOR /L %%t IN (1,1,%stop%) DO title Now pinging: %net%.%%t & echo Now pinging: %net%.%%t & ping -w %timeout% -n %requests% %net%.%%t | find /i "TTL" && echo Found: %net%.%%t >> ipaddresses.txt && tracert -w %timeout% -h %requests% %net%.%%t | find " ms " >> ipaddresses.txt
goto eof
: Rearrange the date and time and set a completion date and time variable
:eof
@for /f "Tokens=1" %%c in ('time /t') do @set tc=%%c
@for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do @set dc=%%i%%j%%k%%l
@set tc=%tc::=.%
@set dtc=%dc% %tc%
echo. >> ipaddresses.txt
echo Scan completed at: %dtc% >> ipaddresses.txt
echo. >> ipaddresses.txt
echo.
echo Results saved to: %~dp0ipaddresses.txt
echo.
goto quit
:quit
@pause
@exit