 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
ezuk
Joined: 04 Jun 2005 Posts: 136
|
Posted: Tue Nov 24, 2009 7:19 am Post subject: [Solved] Execute an action on low bandwidth |
|
|
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 |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 767 Location: The Shell
|
|
| Back to top |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 767 Location: The Shell
|
Posted: Tue Nov 24, 2009 11:21 am Post subject: |
|
|
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 |
|
 |
ezuk
Joined: 04 Jun 2005 Posts: 136
|
Posted: Tue Nov 24, 2009 11:30 am Post subject: |
|
|
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 |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 767 Location: The Shell
|
Posted: Tue Nov 24, 2009 2:00 pm Post subject: |
|
|
Sorry about that, I assumed the received bytes was at character position 24 ..
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 |
|
 |
ezuk
Joined: 04 Jun 2005 Posts: 136
|
Posted: Tue Nov 24, 2009 2:54 pm Post subject: |
|
|
That works perfectly!
Thank you very much! |
|
| Back to top |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 767 Location: The Shell
|
Posted: Tue Nov 24, 2009 3:15 pm Post subject: |
|
|
If you have any problems with the subroutine feel free to post what you have and I will take a look .. _________________
Off diving into dll functions.. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|