Computing.Net > Forums > Programming > DOS Network Meter

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

DOS Network Meter

Reply to Message Icon

Name: keridbey
Date: February 25, 2008 at 10:01:13 Pacific
OS: WinXP
CPU/Ram: 1.83 Ghz / 1 Gb
Product: Dell
Comment:

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 BEGIN

Basically, 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?



Sponsored Link
Ads by Google

Response Number 1
Name: cup
Date: February 27, 2008 at 12:20:00 Pacific
Reply:

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 BEGIN

with

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 :eof

I'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.


0

Response Number 2
Name: cup
Date: February 27, 2008 at 12:29:22 Pacific
Reply:

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


0

Response Number 3
Name: keridbey
Date: February 28, 2008 at 09:45:11 Pacific
Reply:

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 :eof

It 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!!!


0

Response Number 4
Name: cup
Date: February 28, 2008 at 15:03:38 Pacific
Reply:

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


0

Response Number 5
Name: keridbey
Date: March 3, 2008 at 05:17:23 Pacific
Reply:

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!!!


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: DOS Network Meter

VB6 Recent Projects www.computing.net/answers/programming/vb6-recent-projects/1037.html

Need Advice\Socket Programming www.computing.net/answers/programming/need-advicesocket-programming/3115.html

batch printer removal www.computing.net/answers/programming/batch-printer-removal/19552.html