Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a DOS network meter, but I'm trying to shorten it. Below is an simplified version of the program:
@echo off
:BEGIN
set DownDisplay=[ ]
set UpDisplay=[ ]
set down1=
set up1=
set down2=
set up2=
for /F "tokens=2" %%a in ('"netstat -e | find /I "byte""') do set down1=%%a
for /F "tokens=3" %%a in ('"netstat -e | find /I "byte""') do set up1=%%a
ping 127.0.0.1 -n 2 >nul
for /F "tokens=2" %%a in ('"netstat -e | find /I "byte""') do set /A down2=(%%a-%down1%)/1390
for /F "tokens=3" %%a in ('"netstat -e | find /I "byte""') do set /A up2=(%%a-%up1%)/1024
cls
echo.
if %down2% EQU 1 set DownDisplay=[I ]
if %down2% EQU 2 set DownDisplay=[II ]
if %down2% EQU 3 set DownDisplay=[III ]
if %down2% EQU 4 set DownDisplay=[IIII ]
if %down2% EQU 5 set DownDisplay=[IIIII]
if %up2% EQU 1 set UpDisplay=[I ]
if %up2% EQU 2 set UpDisplay=[II ]
if %up2% EQU 3 set UpDisplay=[III ]
if %up2% EQU 4 set UpDisplay=[IIII ]
if %up2% EQU 5 set UpDisplay=[IIIII]
echo %DownDisplay%
echo %UpDisplay%
ping 127.0.0.1 -n 2 >nul
goto BEGINBasically, I'm trying to find a way to have only a few lines devoted to determining how many "I"s to display (my actual program would need over 50 lines to do it). I hope I'm just missing a simple solution. What do you all think?

Initially, I'd replace
if %down2% EQU 1 set DownDisplay=[I ]
if %down2% EQU 2 set DownDisplay=[II ]
if %down2% EQU 3 set DownDisplay=[III ]
if %down2% EQU 4 set DownDisplay=[IIII ]
if %down2% EQU 5 set DownDisplay=[IIIII]
if %up2% EQU 1 set UpDisplay=[I ]
if %up2% EQU 2 set UpDisplay=[II ]
if %up2% EQU 3 set UpDisplay=[III ]
if %up2% EQU 4 set UpDisplay=[IIII ]
if %up2% EQU 5 set UpDisplay=[IIIII]
echo %DownDisplay%
echo %UpDisplay%
ping 127.0.0.1 -n 2 >nul
goto BEGINwith
call :show %down2%
call :show %up2%
ping 127.0.0.1 -n 2 >nul
goto begin:show
set disp=[ ]
if %1 EQU 1 set disp=[I ]
if %1 EQU 2 set disp=[II ]
if %1 EQU 3 set disp=[III ]
if %1 EQU 4 set disp=[IIII ]
if %1 EQU 5 set disp=[IIIII]
echo %disp%
goto :eofI've tried using variables inside substrings. Doesn't seem to work. The only way around it seems to be to do the whole thing in vbscript.

This is a lot slower: you may not even need your ping to slow it down
call :show %down2%
call :show %up2%
ping 127.0.0.1 -n 2 >nul
goto :eof:show
set disp=[
set x=%1
:moreI
if %x% GTR 0 (
set disp=%disp%I
set /a x=%x% - 1
goto moreI
)
set x=%1
:moreSP
if %x% LSS 50 (
set disp=%disp%_
set /a x=%x% + 1
goto moreSP
)
set disp=%disp%]
echo %disp%
goto :eof

Here's what I have now:
@echo off
setlocal:START
set downindicator=
set upindicator=
for /F "tokens=2" %%a in ('"netstat -e | find /I "byte""') do set down1=%%a
for /F "tokens=3" %%a in ('"netstat -e | find /I "byte""') do set up1=%%a
for /F "tokens=2" %%a in ('"netstat -e | find /I "byte""') do set /A down2=(%%a-%down1%)/1390
for /F "tokens=3" %%a in ('"netstat -e | find /I "byte""') do set /A up2=(%%a-%up1%)/1024
cls
echo.call :show %down2%
call :show %up2%
ping 1.1.1.1 -n 1 -w 1000>nul
goto START:show
set disp=[
set x=%1
:moreI
if %x% GTR 0 (
set disp=%disp%I
set /a x=%x% - 1
goto moreI
)
set x=%1
:moreSP
if %x% LSS 50 (
set disp=%disp%_
set /a x=%x% + 1
goto moreSP
)
set disp=%disp%]
echo %disp%
goto :eofIt works really well, almost too good. When the amount of network traffic gets high, the "I"s kind of spill over and fill the DOS window. Would there be a way to modify your code to let it indicate that every five "I"s indicates 100 kb transferred? Hopefully that wouldn't require a lot of extra code.
Thanks!!!

What sort of figures are you getting? You can scale it down by whatever you wish. In :show
set /a x=%1/100
That will scale it down by 100

You're good. :D Now I see how it's working, and it's so completely simple; it's running like a champ. Thank you so much!!!

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |