AutoHotkey Community

It is currently May 24th, 2012, 9:40 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 59 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
PostPosted: April 3rd, 2007, 8:04 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
It displays the network download/upload KB in progress bar.
I adapted Skan's excellent GUI for HDD Monitor for it:
http://www.autohotkey.com/forum/viewtop ... 890#113890

I assumed the index of the active network adapter's interface is 2.
And, I made it to truncate the rate at 100KB, which I think can be easily adjustable.

Code:
#SingleInstance, Force

Gui, -Caption +Border +AlwaysOnTop +ToolWindow
Gui, Color, EEAA99
Gui, +LastFound
WinSet, TransColor, EEAA99
Gui, Add, Progress,      w100 h10 cGreen -0x1 vDn
Gui, Add, Progress, x+10 w100 h10 cRed   -0x1 vUp
Gui, Show, x780 y3 , NetMeter                  ; Adjust X & Y to suit your screen res

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
}

If !ptr
   ExitApp

SetTimer, NetMeter, On, 1000
Return

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

dnNew := DecodeInteger(ptr + 552)      ; Total Incoming Bytes
upNew := DecodeInteger(ptr + 576)      ; Total Outgoing Bytes

dnRate := Round((dnNew - dnOld) / 1024)
upRate := Round((upNew - upOld) / 1024)

GuiControl,, Dn, %dnRate%
GuiControl,, Up, %upRate%

dnOld := dnNew
upOld := upNew
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
}


PS. I believe the following script mimics 'netstat -e', i.e., blindly add up the total downloaded/uploaded bytes of all interfaces.
I recommend it to the users for whom the first script doesn't work, as a temporary work-around.

Code:
#SingleInstance, Force

Gui, -Caption +Border +AlwaysOnTop +ToolWindow
Gui, Color, EEAA99
Gui, +LastFound
WinSet, TransColor, EEAA99
Gui, Add, Progress,      w100 h10 cGreen -0x1 vDn
Gui, Add, Progress, x+10 w100 h10 cRed   -0x1 vUp
Gui, Show, x780 y3 , NetMeter                  ; Adjust X & Y to suit your screen res

If GetIfTable(tb)
   ExitApp

SetTimer, NetMeter, On, 1000
Return

NetMeter:
dnNew := 0
upNew := 0

GetIfTable(tb)

Loop, % DecodeInteger(&tb)
{
/*  Include this codes to exclude the loopback interface.
   If DecodeInteger(&tb + 4 + 860 * (A_Index - 1) + 516) = 24
      Continue
*/
   dnNew += DecodeInteger(&tb + 4 + 860 * (A_Index - 1) + 552)      ; Total Incoming Octets
   upNew += DecodeInteger(&tb + 4 + 860 * (A_Index - 1) + 576)      ; Total Outgoing Octets
}

dnRate := Round((dnNew - dnOld) / 1024)
upRate := Round((upNew - upOld) / 1024)

GuiControl,, Dn, %dnRate%
GuiControl,, Up, %upRate%

dnOld := dnNew
upOld := upNew
Return


GetIfTable(ByRef tb, bOrder = True)
{
   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
}


Last edited by Sean on April 28th, 2007, 1:35 am, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2007, 2:22 pm 
It doesn't work with mine. I tried both wired and wireless connections and doesn't work with any of them. What can be adjusted to try and make it work with mine?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2007, 2:41 pm 
Of course. Just send your computer to Sean, and he will see what is wrong...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2007, 3:34 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Timothy wrote:
It doesn't work with mine. I tried both wired and wireless connections and doesn't work with any of them. What can be adjusted to try and make it work with mine?

What does the following code display?

Code:
MsgBox % GetIfTable()


GetIfTable(bOrder = True)
{
   DllCall("iphlpapi\GetNumberOfInterfaces", "UintP", nIf)
   nSize := 4 + 860 * nIf + 8
   VarSetCapacity(tbl, nSize)
   DllCall("iphlpapi\GetIfTable", "Uint", &tbl, "UintP", nSize, "int", bOrder)

   Loop, %nIf%
         Interfaces .= DecodeInteger(&tbl + 4 + 512 + 860 * (A_Index - 1)) . " : " . DecodeInteger(&tbl + 4 + 516 + 860 * (A_Index - 1)) . " : " . DecodeInteger(&tbl + 4 + 544 + 860 * (A_Index - 1)) . "`n"

   Return Interfaces
}

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2007, 7:26 pm 
1 : 24 : 5
65539 : 6 : 5
65540 : 6 : 0
65541 : 6 : 0


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2007, 9:56 pm 
Offline

Joined: April 20th, 2006, 9:54 pm
Posts: 21
It did not work for me also because I have all sorts of virtual network interfaces (for vpn and vmware).

I did the following:

Type the this command in a command prompt and check the output. The output will list all your network interfaces.

Code:
ipconfig /all


Check the position of the correct network interface. The first entry is your hostname, below that is the list of network interfaces. For me the sixth entry was the correct one so I replaced the 2 at the end of this line to 6.

Code:
DllCall("RtlFillMemory", "Uint", &tb + 512, "Uint", 1, "Uchar", 2)   ; 1-based index of the interface including loopback


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2007, 11:30 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Timothy wrote:
1 : 24 : 5
65539 : 6 : 5
65540 : 6 : 0
65541 : 6 : 0

Is this correct? If it's correct, you have to replace

Code:
DllCall("RtlFillMemory", "Uint", &tb + 512, "Uint", 1, "Uchar", 2)

with

Code:
DllCall("ntdll\RtlFillMemoryUlong", "Uint", &tb + 512, "Uint", 4, "Uint", 65539)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2007, 11:47 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
bold wrote:
It did not work for me also because I have all sorts of virtual network interfaces (for vpn and vmware).

You figured it out yourself very nicely in spite of my poor explanation. Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2007, 9:03 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Well, everybody have couple nowdays.
Sean, can you fix it not to depend on this ?

Take one as default and let user choose another one via menu or something ? Or, display all at start and let the user hide unwanted connections.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2007, 10:24 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Very nice, Sean. :D

BTW, do you know how to ascertain the bytes received & sent ( as shown in LAN status ) ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2007, 1:39 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
majkinetor wrote:
Well, everybody have couple nowdays.
Sean, can you fix it not to depend on this ?

I modified it as to detect the active one and then to start monitoring it.
I'm still not sure if it'll always pick out the correct one.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2007, 1:41 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Hej, it works here now :D
Can you close it in function, like:

Code:
  GetNetworkLoad( networkID="A" )

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2007, 1:45 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Skan wrote:
Very nice, Sean. :D

Thanks! It's your GUI, BTW. :)

Quote:
BTW, do you know how to ascertain the bytes received & sent ( as shown in LAN status ) ?

I'm not sure if I understand you correctly, but the dnNew/upNew is the total bytes (:which is mostly octets these days) received/sent up to now. Is this the proper answer?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2007, 2:10 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
majkinetor wrote:
Hej, it works here now :D

Good to know. Thanks.

Quote:
Can you close it in function, like:

Code:
  GetNetworkLoad( networkID="A" )

Do you mean like GetIfEntry(ByRef tb, idx)?
It's already there, however, I didn't use it as I couldn't decide whether incorporating offset is good or not.

PS. Oops, I forgot idx.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2007, 3:55 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Sean wrote:
Skan wrote:
BTW, do you know how to ascertain the bytes received & sent ( as shown in LAN status ) ?

I'm not sure if I understand you correctly, but the dnNew/upNew is the total bytes (:which is mostly octets these days) received/sent up to now. Is this the proper answer?


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

I had been wanting to write a bandwidth usage solution for my customised needs, but have never been successful in fetching the exact Sent/Recvd bytes. :( .. Related : Bandwidth Meter/Measurer

Sean wrote:
I made it to truncate the rate at 100KB, which I think can be easily adjustable


FYI:

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

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

Thanks .. :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 59 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group