Michael said:
[snip][173 lines snipped]
A more concise solution using 4NT:
Hello Michael,
I had the same idea converting the ip number to an integer and
experienced the same problems with the cmd.exe for using a signed 32bit
integer for math. Since I prefer free solutions I used conset from Frank
P. Westlake which uses 64bit integers.
Took me some time to get rid of strange behaviour while using delayed
expansion, after disabling all was fine in w2k.
My batch output resembles more the op's one. There are functions inside
conset which look like your 4nt code, I still have to dive in there.
FWIW Here is my batch requiring conset
http://gearbox.maem.umr.edu/fwu/
<snip>
::MyIPScanner.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off&setlocal&cls
set log="%USERPROFILE%\Desktop\ip_scan_results.txt"
echo.=========================== MyIP scanner =======================
:S_IP Start IP input
set "MiS="
set /P MiS=Enter dotted start IP address i.e. 192.168.1.1 :
if {%MiS%}=={} echo bye, bye&exit /B
:: The following line will call the sub with input-dots replaced
:: by spaces giving %1..%4 in the sub with the var name appended (%5)
Call :CheckIP %MiS:.= % MiS||(echo %MiS% isn't a valid IP&goto :S_IP)
:E_IP End IP Input
set /P MiE=Enter dotted end IP address i.e. 192.168.1.9 :
Call :CheckIP %MiE:.= % MiE||(echo %MiE% isn't a valid IP&goto :E_IP)
:: Calculate the range by subtracting start IP int from end IP int
:: Due to 32bit signed int use of set we need conset (64bit integers)
conset /A "MiRange=MiEI-MiSI"
If %MiRange% LSS 0 (echo.Start greater End IP!&goto :S_IP)
if %MiRange% GTR 1000 (echo Range greater than 1000&goto :S_IP)
Call :LogHeader
::set Mi&pause Just for debugging purposes
set /A MiPing=0,MiLost=0,MiIntermittent=0
for /L %%A in (0 1 %MiRange%) do call :MyPing %MiSI% %%A
:: Output summary to log filestart "" /MAX %log%
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:CheckIP 4 octets (by val) and MiS/MiE (by ref)
if "%~5" EQU "" echo Not 4 octets! &exit /B 1
if %5 NEQ MiS if %5 NEQ MiE echo Not 4 octets! &exit /B 1
:: Get the input value to MiC (make val from ref) & reset integer
setlocal&call set "MiC=%%%5%%"&set /A MiCI=0
:: Build 32bit integer by shiffting Octets to the proper place.
:: reversed byte order has to be taken into account
for /L %%A in (1 1 4) do (
call conset /AX "MiCI+=(%%%%A &255)<<(8*(4-%%A))")
::Calc IP octets from 32bit Int
for /L %%A in (1 1 4) do (
call conset /A "MiC%%A=(MiCI&255<<(8*(4-%%A)))>>(8*(4-%%A))")
:: Compare numbers with input - if equal IP is well formed
if "%MiC%" NEQ "%MiC1%.%MiC2%.%MiC3%.%MiC4%" exit /B 1
endlocal&set "%5I=%MiCI%"&exit /B 0
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:MyPing offset cnt (by val)
:: Decode 32bit integer to 4 octets
for /L %%A in (1 1 4) do (
conset /A "O%%A=((%1+%2)&(255<<8*(4-%%A)))>>8*(4-%%A)")
set IP=%O1%.%O2%.%O3%.%O4%
echo Checking %IP%
for /f "tokens=3,5,7,8 delims==, " %%A in (
'ping -n 1 -w 50 -n 6 %IP%^|find "("') do (
IF %%A EQU %%B (set /A MiPing+=1
echo %IP% ok>>%log%
) else (if %%A EQU %%C (set /A MiLost+=1
) else (set /A MiIntermittent+=1
echo %IP% lost %%D>>%log%
) ) )
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:LogHeadergoto :eof
::MyIPScanner.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::