AutoHotkey Community

It is currently May 27th, 2012, 2:46 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: November 24th, 2009, 8:19 am 
Offline

Joined: June 4th, 2005, 1:54 am
Posts: 146
Hello,

I've searched the forum and found a few complex-looking bandwidth meters, meant to display current use graphically.

I just want a non-GUI script which would silently monitor traffic, and if less than X bytes are transferred in Y minutes, would do something (execute a subroutine).

Any ideas, how would I go about that? The existing bandwidth monitors are very complex -- it's hard for me to extract the simple code I need from them.

An external utility is an option too, by the way, if you know of one.

Thanks!


Last edited by ezuk on November 24th, 2009, 3:55 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2009, 11:20 am 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Working on something.

In the meantime the free monitor from analogX may be of interest to you:
http://www.analogx.com/contents/downloa ... eeware.htm

It has an installer :(, if thats not your thing Sandbox it
http://www.sandboxie.com/

brb

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2009, 12:21 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Try this:

Code:
nstFile = % A_Desktop "\BW_TXT.txt"

Gui, Add, Text,, Current Bandwidth:
Gui, Add, Text, W100 vbwTxt, Loading...
Gui, Show, NA, BW

Loop,
{
    RunWait %comspec% /c ""Netstat" "-e" >"%nstFile%"",, Hide
    Loop, Read, % nstFile
   {
   curBandWidth := A_LoopReadLine
   if curBandWidth contains Bytes
       StringSplit, curBandWidth, curBandWidth, % A_Space
       GuiControl, Text, bwTxt, % "Bytes: " curBandWidth24
   }
}

GuiClose:
ExitApp


It gives the bandwidth in bytes. Its pretty simple to add a condition that will alert you if it goes over or below a certain byte count.

Let me know if this is of interest...

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2009, 12:30 pm 
Offline

Joined: June 4th, 2005, 1:54 am
Posts: 146
Interesting approach!

Doesn't exactly work. The file does get created, but the GUI still says "loading" for some reason.

File contents:

Code:
Interface Statistics

                           Received            Sent

Bytes                    2373269937      1951324305
Unicast packets            18678597        10966590
Non-unicast packets            3231           11724
Discards                          0               0
Errors                            0               0
Unknown protocols                 0


So the StringSplit should work. Not quite sure why the interface says nothing.

I did this:

Code:
nstFile = "BW_TXT.txt"

Gui, Add, Text,, Current Bandwidth:
Gui, Add, Text, W100 vbwTxt, Loading...
Gui, Show, NA, BW

Loop,
{
    RunWait %comspec% /c ""Netstat" "-e" >"%nstFile%"",, Hide
    Loop, Read, % nstFile
   {
   curBandWidth := A_LoopReadLine
   if curBandWidth contains Bytes
       StringSplit, curBandWidth, curBandWidth, % A_Space
       GuiControl, Text, bwTxt, % "Bytes: " curBandWidth24
       msgbox %curBandWidth%
   }
}

GuiClose:
ExitApp


And the messagebox never showed up.. So I guess the process won't quit, or something. Does it work for you?

It's a good start, anyway! Using Netstat I can probably figure something out myself, too.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2009, 3:00 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Sorry about that, I assumed the received bytes was at character position 24 :oops:..

Try this instead. its a simple parse.

Code:
nstFile = % A_Desktop "\BW_TXT.txt"

Gui, Add, Text,, Current Bandwidth:
Gui, Add, Text, W140 vbwTxt, Loading...
Gui, Show, NA, BW

Loop,
{
    RunWait %comspec% /c ""Netstat" "-e" >"%nstFile%"",, Hide
    FileReadLine, bytesLine, % nstFile, 5
   StringReplace, bytesLine, bytesLine, Bytes,
   bytesData = %bytesLine%
   StringSplit, bytesData, bytesData, % A_Space
       GuiControl, Text, bwTxt, % "In Bytes: " bytesData1
}

GuiClose:
ExitApp



Let me know how this works out..
hth


edit:

I just read the 1st post again and noticed you also wanted to know how many bites in X minutes.

For that you want to create a byte stamp using the variable bytesData1 at A_Now (when the script starts) and then subtract the current bytesData1 from the initial byte stamp when A_Now reaches desire length of time (so you'll need a variable and condition for that also).

hth

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2009, 3:54 pm 
Offline

Joined: June 4th, 2005, 1:54 am
Posts: 146
That works perfectly!

Thank you very much!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2009, 4:15 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
If you have any problems with the subroutine feel free to post what you have and I will take a look ;)..

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: rbrtryn, XstatyK and 21 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group