Jump to content

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

Network Download/Upload Meter


  • Please log in to reply
60 replies to this topic
majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006

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

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

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.

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.

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.

The current version automatically selects.. :!: :D For the previous version I had to alter the RtlFill... to 1 instead of 2.

Oh, another success. Thanks for informing me.

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

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.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

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

:roll:

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

I am confused :(. 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.

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

Paulo-nli
  • Guests
  • Last active:
  • Joined: --
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??)
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... :p :p

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Hi, this script is great,thanks Sean.

Thanks.

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

SetTimer, NetMeter, 1000
I think it will create the timer with the deafult period 250ms.

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

Yes, that can easily escape the users...

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
... NetMeter

Posted Image

#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, https://ahknet.autohotkey.com/~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:
[*:3qzhabzr]The Gui displays Bytes Sent/Received, KB/s, Total MB
[*:3qzhabzr]An Icon on the Gui as well as the tray Icon reflects the status.
[*:3qzhabzr]Double click the Tray icon to Show/Hide the GUI. ( Thanks majkinetor )
[*:3qzhabzr]Right click on the GUI to display the Tray menu.
[*:3qzhabzr]Drag and locate the GUI to the desired position. The Location will be remembered.
[*:3qzhabzr]Dynamic polling. Polls per 256ms during activity, per 1024ms when inactive.
[*:3qzhabzr]Less GUI flicker. ( Thanks majkinetor )Credits:
[*:3qzhabzr]Sean, Ofcourse
[*:3qzhabzr]toralf, for his wonderful Icon Viewer v6 + Lite v2 ( I use the lite version )
[*:3qzhabzr]majkinetor, for the valuable suggestions.
Thanks Sean .. :)

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

[*:3k8b1b6w]The Gui displays Bytes Sent/Received, KB/s, Total MB
[*:3k8b1b6w]An Icon on the Gui as well as the tray Icon reflects the status.
[*:3k8b1b6w]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.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
/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.
Posted Image

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
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:
[color=blue]   if (iNo != lastNo)[/color]
	   GuiControl,, Icon, *Icon%iNo% NetShell.dll
   Menu, Tray, Icon, NetShell.dll, % iNo+14

   dnOld := dnNew , upOld := upNew
   SetTimer, NetMeter, %PollMs%
[color=blue]   lastNo := iNo[/color]

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

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Sean: Thanks for the very nice words. :)

majkinetor:

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.

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


Many thanks. I have updated the code.

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.

:D

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
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).
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.

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

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

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.

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.

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.

steliyan
  • Members
  • 48 posts
  • Last active: Jan 29 2015 04:14 PM
  • Joined: 20 Apr 2007
Doesn't show the current speed (shows ~350KB/s), but I'm restricted to 256KB/s.