Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Solved] Execute an action on low bandwidth


  • Please log in to reply
7 replies to this topic
ezuk
  • Members
  • 149 posts
  • Last active: Jan 02 2013 08:54 AM
  • Joined: 04 Jun 2005
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!

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Working on something.

In the meantime the free monitor from analogX may be of interest to you:
<!-- m -->http://www.analogx.c... ... eeware.htm<!-- m -->

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

brb

Posted Image

don't duplicate, iterate!


TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Try this:

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

Posted Image

don't duplicate, iterate!


ezuk
  • Members
  • 149 posts
  • Last active: Jan 02 2013 08:54 AM
  • Joined: 04 Jun 2005
Interesting approach!

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

File contents:

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:

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.

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Sorry about that, I assumed the received bytes was at character position 24 :oops:..

Try this instead. its a simple parse.

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

Posted Image

don't duplicate, iterate!


ezuk
  • Members
  • 149 posts
  • Last active: Jan 02 2013 08:54 AM
  • Joined: 04 Jun 2005
That works perfectly!

Thank you very much!

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
If you have any problems with the subroutine feel free to post what you have and I will take a look ;)..

Posted Image

don't duplicate, iterate!


derders
  • Members
  • 1 posts
  • Last active: Nov 04 2014 08:52 PM
  • Joined: 31 Oct 2014

HI and sorry to reactivate an old thread like this

 

but I searched web and found it and wanted to ask you TLM (or others) if you could help me to make a script like this

 

 

what I need is:

 

An AHK script that execute a file if download speed (if possible of a single program if not global) drops below a certain threshold (100 kB/s)

without GUI would be enough

 

 

I am a noob in such things and can`t find something similar

 

would be very nice to get some help