AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Solved] Execute an action on low bandwidth

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
ezuk



Joined: 04 Jun 2005
Posts: 136

PostPosted: Tue Nov 24, 2009 7:19 am    Post subject: [Solved] Execute an action on low bandwidth Reply with quote

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 Tue Nov 24, 2009 2:55 pm; edited 1 time in total
Back to top
View user's profile Send private message
TLM



Joined: 21 Aug 2006
Posts: 767
Location: The Shell

PostPosted: Tue Nov 24, 2009 10:20 am    Post subject: Reply with quote

Working on something.

In the meantime the free monitor from analogX may be of interest to you:
http://www.analogx.com/contents/download/Network/nsl/Freeware.htm

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

brb
_________________

Off diving into dll functions..
Back to top
View user's profile Send private message
TLM



Joined: 21 Aug 2006
Posts: 767
Location: The Shell

PostPosted: Tue Nov 24, 2009 11:21 am    Post subject: Reply with quote

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

Off diving into dll functions..
Back to top
View user's profile Send private message
ezuk



Joined: 04 Jun 2005
Posts: 136

PostPosted: Tue Nov 24, 2009 11:30 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
TLM



Joined: 21 Aug 2006
Posts: 767
Location: The Shell

PostPosted: Tue Nov 24, 2009 2:00 pm    Post subject: Reply with quote

Sorry about that, I assumed the received bytes was at character position 24 Embarassed..

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
_________________

Off diving into dll functions..
Back to top
View user's profile Send private message
ezuk



Joined: 04 Jun 2005
Posts: 136

PostPosted: Tue Nov 24, 2009 2:54 pm    Post subject: Reply with quote

That works perfectly!

Thank you very much!
Back to top
View user's profile Send private message
TLM



Joined: 21 Aug 2006
Posts: 767
Location: The Shell

PostPosted: Tue Nov 24, 2009 3:15 pm    Post subject: Reply with quote

If you have any problems with the subroutine feel free to post what you have and I will take a look Wink..
_________________

Off diving into dll functions..
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group