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 

Network Download/Upload Meter
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
majkinetor



Joined: 24 May 2006
Posts: 3593
Location: Belgrade

PostPosted: Wed Apr 04, 2007 5:24 pm    Post subject: Reply with quote

Quote:
Do you mean like GetIfEntry(ByRef tb, idx)?

I didn't dive into source code here, so I don't know what this function does. I ment about the function that will return usage procentage, similar to Laszlo's GetCPULoad(). The function should account different network adapters or even allow enumeration.
_________________
Back to top
View user's profile Send private message MSN Messenger
Sean



Joined: 12 Feb 2007
Posts: 1249

PostPosted: Wed Apr 04, 2007 11:47 pm    Post subject: Reply with quote

Skan wrote:
It does not match the bytes sent/recvd shown in my Local Area Connection Status dialog!

Ah, that's not the number of bytes, but the number of packets, at least in my system.

Code:
upPackets := DecodeInteger(ptr + 580) + DecodeInteger(ptr + 584)
dnPackets := DecodeInteger(ptr + 556) + DecodeInteger(ptr + 560)

The first ones are for unicast, and the last ones are for multicast/broadcast.
Strangely, the status dialog in my case didn't count the non-unicast, i.e., the last one, for dnPackets, but did so for upPackets.

Quote:
I have a rather slow ADSL connection On Ethernet in W2K OS. The progress bar does not budge until I remove the "/ 1024"

That's too bad... In my case, 100KB is too small, it's truncated too frequently.

Quote:
The current version automatically selects.. Exclamation Very Happy For the previous version I had to alter the RtlFill... to 1 instead of 2.

Oh, another success. Thanks for informing me.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1249

PostPosted: Thu Apr 05, 2007 1:23 am    Post subject: Reply with quote

majkinetor wrote:
The function should account different network adapters or even allow enumeration.

I think this is perfectly fit into ListView, in conjunction with TreeView. It provides very detailed information about the adapters like MAC address etc. I may do it if I'm ever accustomed to AHK's GUI. I've never had a chance to read about it thoroughly up to now.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5581

PostPosted: Thu Apr 05, 2007 6:55 am    Post subject: Reply with quote

Sean wrote:
Skan wrote:
It does not match the bytes sent/recvd shown in my Local Area Connection Status dialog!

Ah, that's not the number of bytes, but the number of packets, at least in my system.


I am confused Sad. The dialog shows it as "Bytes Sent" and "Bytes Recieved".
It would be helpful if somebody could throw light on this.

The Script,
Local Area Connection Status dialog,
NetStat -e

All the three show different values. The latter two are somewhat closer in figures.

Rolling Eyes
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1249

PostPosted: Thu Apr 05, 2007 8:46 am    Post subject: Reply with quote

Skan wrote:
I am confused Sad. The dialog shows it as "Bytes Sent" and "Bytes Recieved".
It would be helpful if somebody could throw light on this.

The help (:right-click the data type in the dialog and choose desc) tells that it indeed can be bytes or packets.
I reckon it depends on the speed of the connection.

Quote:
The Script,
Local Area Connection Status dialog,
NetStat -e

All the three show different values. The latter two are somewhat closer in figures.

netstat really produced different results from the script, in my system too.
I observed, however, that it always produced greater values for the data bytes and for the unicast packets,
but, the same value for the non-unicast packets.
It led me readily to the conjecture that netstat may combine the vlues of the active adapter and those of the loopback.
And, I confirmed it in my system.

The purpose of the following condition was to filter out the loopback.
Code:
DecodeInteger(&tb + 4 + 860 * (A_Index - 1) + 516) = 24

I'm not sure why netstat counts also the values of the loopback. It appears to be rather pointless to me.
Back to top
View user's profile Send private message
Paulo-nli
Guest





PostPosted: Thu Apr 05, 2007 8:49 am    Post subject: Reply with quote

Hi, this script is great,thanks Sean.

The script is showing different values because the timer is not set to 1s.
I guess it is just a mistake(or not??)
Code:

SetTimer, NetMeter, on, 1000
should be
SetTimer, NetMeter, 1000


I remember when I was looking for a way to measure the bandwidth usage and found the GetIfEntry function and I thougth...
I want bytes and not octets... Razz Razz
Back to top
Sean



Joined: 12 Feb 2007
Posts: 1249

PostPosted: Thu Apr 05, 2007 9:10 am    Post subject: Reply with quote

Paulo-nli wrote:
Hi, this script is great,thanks Sean.

Thanks.

Quote:
The script is showing different values because the timer is not set to 1s.
I guess it is just a mistake(or not??)

Code:
SetTimer, NetMeter, 1000

I think it will create the timer with the deafult period 250ms.

Quote:
I remember when I was looking for a way to measure the bandwidth usage and found the GetIfEntry function and I thougth...
I want bytes and not octets... Razz Razz

Yes, that can easily escape the users...
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5581

PostPosted: Sun Apr 08, 2007 7:18 am    Post subject: Reply with quote

... NetMeter



Code:
#SingleInstance, Force
DetectHiddenWindows, OFF             ; OFF is default, but this script would err if set ON

Menu, Tray, NoStandard
Menu, Tray, Add, Show/Hide, ShowHide
Menu, Tray, Add
Menu, Tray, Standard
Menu, Tray, Default, Show/Hide
Menu, Tray, Icon, NetShell.dll, 58

IfNotExist, %A_Temp%\NetStatus.bmp
UrlDownloadToFile, http://www.autohotkey.net/~goyyah/samples/grad001.bmp
, %A_Temp%\NetStatus.bmp

Gui -Caption +Border +ToolWindow +AlwaysOnTop +LastFound
GuiID := WinExist() , prv_iNo := 44
Gui, Color , FFFFEE
Gui, Margin, 0, 0
Gui, Font  , s8, Verdana
Gui, Add, Picture, x40   y0   w200 h40 vConn  GuiMove, %A_Temp%\NetStatus.bmp
Gui, Add, Picture, x5    y6     Icon30 vIcon  GuiMove, NetShell.dll
Gui, Add, Text   , x+7   y3    w75  h16 +Border
Gui, Add, Text   , xp+1  yp+1  w70  h14 +0x200 c5B0000 +Right  HWNDSent
Gui, Add, Text   , xp-1  y+3   w75  h16 +Border
Gui, Add, Text   , xp+1  yp+1  w70  h14 +0x200 c5B0000 +Right  HWNDRecv
Gui, Add, Text   , x+7   y3    w80  h16 +Border   
Gui, Add, Text   , xp+4  yp+1  w75  h14 c003D00                HWNDkbps 
Gui, Font, Bold
Gui, Add, Text   , xp-4  y+3   w80  h16 +Border
Gui, Add, Text   , xp+4  yp+1  w75  h14 c003D00                HWNDband 

IniRead, X, %A_Temp%\%A_ScriptName%.INI, GuiPos, XPos, 20
IniRead, Y, %A_Temp%\%A_ScriptName%.INI, GuiPos, YPos, 20

Gui, Show, x%x% y%y% w205 h40, NetMeter

If GetIfTable(tb)
   ExitApp

Loop, % DecodeInteger(&tb) {
   If DecodeInteger(&tb + 4 + 860 * (A_Index - 1) + 544) < 4
   || DecodeInteger(&tb + 4 + 860 * (A_Index - 1) + 516) = 24
      Continue

   ptr := &tb + 4 + 860 * (A_Index - 1)
      Break
                           }
IfLess, ptr, 1, ExitApp
SetTimer, NetMeter

Return ; ------------------------------------------------------- AutoExecute Section ends

NetMeter:
   SetTimer, NetMeter, Off
   DllCall("iphlpapi\GetIfEntry", "Uint", ptr)

   dnNew := DecodeInteger(ptr + 552)   ,    upNew  := DecodeInteger(ptr + 576)     
   dnRate := Round((dnNew - dnOld) )   ,    upRate := Round((upNew - upOld) )
   PollMs := (dnRate - upRate = 0) ? 1024 : 256

   Menu, Tray, Tip, % "Sent: " upNew " / Recv: " dnNew " / Total: "
                  . Round((((upNew+dnNew) /1024)/1024),1) . " MB"

   ; Determine & update GUI-Icon & Tray-Icon
   IfGreater,dnRate,0,  IfGreater,upRate,0,  SetEnv,iNo,41     ;  Recv/Sent
   IfGreater,dnRate,0,  IfEqual  ,upRate,0,  SetEnv,iNo,42     ;  Recv
   IfEqual  ,dnRate,0,  IfGreater,upRate,0,  SetEnv,iNo,43     ;  Sent
   IfEqual  ,dnRate,0,  IfEqual  ,upRate,0,  SetEnv,iNo,44     ;  None
   IfNotEqual,iNo, %prv_iNo%,  Menu, Tray, Icon, NetShell.dll, % iNo+14

   If WinExist( "ahk_id " . GuiID )  {                ; Update the GUI Data
   ControlSetText,, %upNew%                                         , ahk_id %Sent%   
   ControlSetText,, %dnNew%                                         , ahk_id %Recv%
   ControlSetText,, % Round((dnrate+uprate)/PollMs) . " KBps"       , ahk_id %Kbps%
   ControlSetText,, % Round((((upNew+dnNew) /1024)/1024),1) . " MB" , ahk_id %Band%
   IfNotEqual,iNo, %prv_iNo%,  GuiControl,, Icon, *Icon%iNo% NetShell.dll
                                     }

   prv_iNo := iNo , dnOld := dnNew , upOld := upNew
   SetTimer, NetMeter, %PollMs%
Return

uiMove:
   PostMessage, 0xA1, 2,,, A
   Sleep 200
   WinGetPos, X, Y
   IniWrite, %X%, %A_Temp%\%A_ScriptName%.INI, GuiPos, XPos
   IniWrite, %Y%, %A_Temp%\%A_ScriptName%.INI, GuiPos, YPos
Return

ShowHide:
   GuiControl,, Icon, *Icon%iNo% NetShell.dll
   IfWinExist, ahk_id %GuiID%,,,, WinHide, ahk_id %GuiID%
   Else                           WinShow, ahk_id %GuiID%
Return

GuiContextMenu:
   Menu, Tray, Show
Return

GetIfTable(ByRef tb, bOrder = False) {
   nSize := 4 + 860 * GetNumberOfInterfaces() + 8
   VarSetCapacity(tb, nSize)
   Return DllCall("iphlpapi\GetIfTable", "Uint", &tb, "UintP", nSize, "int", bOrder)
                                     }

GetIfEntry(ByRef tb, idx)            {
   VarSetCapacity(tb, 860)
   DllCall("ntdll\RtlFillMemoryUlong", "Uint", &tb + 512, "Uint", 4, "Uint", idx)
   Return DllCall("iphlpapi\GetIfEntry", "Uint", &tb)
                                     }

GetNumberOfInterfaces()              {
   DllCall("iphlpapi\GetNumberOfInterfaces", "UintP", nIf)
   Return nIf
                                     }

DecodeInteger(ptr)                   {
   Return *ptr | *++ptr << 8 | *++ptr << 16 | *++ptr << 24
                                     }


Notes:
  • The Gui displays Bytes Sent/Received, KB/s, Total MB
  • An Icon on the Gui as well as the tray Icon reflects the status.
  • Double click the Tray icon to Show/Hide the GUI. ( Thanks majkinetor )
  • Right click on the GUI to display the Tray menu.
  • Drag and locate the GUI to the desired position. The Location will be remembered.
  • Dynamic polling. Polls per 256ms during activity, per 1024ms when inactive.
  • Less GUI flicker. ( Thanks majkinetor )

Credits:
  • Sean, Ofcourse
  • toralf, for his wonderful Icon Viewer v6 + Lite v2 ( I use the lite version )
  • majkinetor, for the valuable suggestions.


Thanks Sean .. Smile


Last edited by SKAN on Tue Apr 10, 2007 2:38 pm; edited 2 times in total
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1249

PostPosted: Sun Apr 08, 2007 12:06 pm    Post subject: Reply with quote

Skan wrote:
  • The Gui displays Bytes Sent/Received, KB/s, Total MB
  • An Icon on the Gui as well as the tray Icon reflects the status.
  • Drag and locate the GUI to the desired position. The Location will be remembered.

Superb! I almost thought I was seeing a commercial application. Very professional touch. Thanks for sharing it.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3593
Location: Belgrade

PostPosted: Sun Apr 08, 2007 12:24 pm    Post subject: Reply with quote

/Applaud

NOTE: Red text flickers a lot. It seems that design of the GUI is such that +BacgroundTrans, togegether with drowing over another control makes text flicker. Icon flickers too

Feature: Click on the tray show hide gui.
_________________
Back to top
View user's profile Send private message MSN Messenger
majkinetor



Joined: 24 May 2006
Posts: 3593
Location: Belgrade

PostPosted: Sun Apr 08, 2007 12:41 pm    Post subject: Reply with quote

It seems to me that flickering is autohotkey problem

If control is drawn over another control with +BackgroundTrans set, you will sometimes see its background visible

Icon has another problem and this code will solve its flickering:
Code:
   if (iNo != lastNo)
      GuiControl,, Icon, *Icon%iNo% NetShell.dll
   Menu, Tray, Icon, NetShell.dll, % iNo+14

   dnOld := dnNew , upOld := upNew
   SetTimer, NetMeter, %PollMs%
   lastNo := iNo


I guess you can fix it with drawing or if Crhis fix this issue as it seems to be AHK related. You can try to avoid GuiControl and to set the text direclty using API to see if there are any changes.

If you set the color of the right statics to match the background it will not flicker, but as you have gradient now, its not going to happen. WIth drawing functions you could solve that, I guess.
_________________
Back to top
View user's profile Send private message MSN Messenger
SKAN



Joined: 26 Dec 2005
Posts: 5581

PostPosted: Sun Apr 08, 2007 2:22 pm    Post subject: Reply with quote

Sean: Thanks for the very nice words. Smile

majkinetor:

Quote:
It seems to me that flickering is autohotkey problem.
If control is drawn over another control with +BackgroundTrans set, you will sometimes see its background visible


Yes! And usually it was less visible with a larger Gui.

Quote:
Icon has another problem and this code will solve its flickering:


Many thanks. I have updated the code.

Quote:
I guess you can fix it with drawing or if Chris fix this issue as it seems to be AHK related. You can try to avoid GuiControl and to set the text direclty using API to see if there are any changes.

If you set the color of the right statics to match the background it will not flicker, but as you have gradient now, its not going to happen. With drawing functions you could solve that, I guess.


I did not think this way. I will try it .. Thank you very much.

Very Happy
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Thu Apr 26, 2007 6:49 pm    Post subject: Reply with quote

This is no big deal because my config isn't typical: Neither the topmost script nor Skan's works on my system, probably because I have a NIC for LAN and another for Internet (so perhaps the script is monitoring the LAN one).
Code:
1 : 24 : 5
65539 : 6 : 5
65540 : 6 : 5

Also, it's probably not at the top of your priorities, but the opening post could use more introduction. Also, the script could use more comments and configuration settings (such as constants that can be easily adjusted at the top of the script; e.g. max speed, force a particular interface number, etc.)

Minor point: I notice that the function GetIfEntry() is defined but never called (maybe intentional).

Thanks.
Back to top
View user's profile Send private message Send e-mail
Sean



Joined: 12 Feb 2007
Posts: 1249

PostPosted: Fri Apr 27, 2007 12:19 am    Post subject: Reply with quote

Chris wrote:
This is no big deal because my config isn't typical: Neither the topmost script nor Skan's works on my system, probably because I have a NIC for LAN and another for Internet (so perhaps the script is monitoring the LAN one).
Code:
1 : 24 : 5
65539 : 6 : 5
65540 : 6 : 5

Ah, this is the configuration I was afraid of where the script won't work.
My lack of knowledge about the configuration of other users made me feel lost in a maze when I set up the script.
Thanks for informing me about your configuration.

As a matter of fact, after discussing with Skan about the discrepancy between the script and netstat.exe, in this very thread, I realized that the loopback (24, in your first interface 1 : 24 : 5, indicates it's a loopback interface) may not be a particular target of netstat.exe. It may simply try to sum up the data of all the interfaces.

So, I may also do it here.
What I'm concerned atm is, however, whether we have to include the loopback interface too or not.
I'd like to hear about the opinion of yours and other users on it.

Quote:
Also, it's probably not at the top of your priorities, but the opening post could use more introduction. Also, the script could use more comments and configuration settings (such as constants that can be easily adjusted at the top of the script; e.g. max speed, force a particular interface number, etc.)

OK, I'll try to incorporate these when I update the script, but I'm feeling that these can be achieved better than me by Skan.

Quote:
Minor point: I notice that the function GetIfEntry() is defined but never called (maybe intentional).

Yes, I left it for completeness.
BTW, if the option to force a particular interface number is implemented, better use it than GetIfTable(), as it's simpler to use.
Back to top
View user's profile Send private message
steliyan



Joined: 20 Apr 2007
Posts: 26

PostPosted: Fri Apr 27, 2007 8:08 am    Post subject: Reply with quote

Doesn't show the current speed (shows ~350KB/s), but I'm restricted to 256KB/s.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
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