Jump to content
Sign in to follow this  
TDD

Using AutoIT as an internet bandwidth monitor...

Recommended Posts

TDD

Hello!

Firstly, i'll refer to the original thread located at: http://www.autoitscript.com/forum/index.php?showtopic=31123

Lod3n created an example, which i've been messing with, but i'm extremely inexperienced with AutoIT (I'd ask him, but he hasn't logged in for a month), and was wondering, does this monitor ALL inbound connections, and outbound, or specifically those to the internet? (As in, does it ignore any connections to 192.168.1.* as that is not internet but LAN). I have a feeling it does include local connections, as when I was doing a backup to my network HDD (192.168.1.103), it increased the outbound a lot...

If it doesn't, how could it be modified to ignore any transfers to 192.168.1.*?

So far I've messed with the code in order to create a total of the downloads and uploads in MB versus bytes, which i'm rather proud of for my first AutoIT code. My ultimate goal is to use it to silently and invisibly log all this information to a text file so that I can use RainMeter to display this on a config, to use it as an internet download quota manager... as the default RainMeter traffic monitor also includes lan.

Thanks,

TDD

By the way, here's the code I have modified from lod3n's:

#include <GUIConstants.au3>

GUICreate("Lod3n's Bandwidth Monitor",220,50,150,150,-1)

$label1 = GUICtrlCreateLabel ( "Waiting for data...", 10, 5,200,20)

$label2 = GUICtrlCreateLabel ( "Waiting for data...", 10, 25,500,20)

GUISetState ()

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")

$inmax = 0
$outmax = 0

$lastin = 0
$lastout = 0

while 1
    ;$colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec FROM Win32_PerfFormattedData_Tcpip_NetworkInterface", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    $colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    
    If IsObj($colItems) then
        For $objItem In $colItems
            $newin = $objItem.BytesReceivedPersec
            $newout = $objItem.BytesSentPersec
            
            ;new realtime counter code...
            if $lastin = 0 and $lastout = 0 Then
                $lastin = $newin
                $lastout = $newout
            endif
            $in = $newin - $lastin
            $out = $newout - $lastout
            $lastin = $newin
            $lastout = $newout

            if $in <> 0 and $out <> 0 Then
                $inmax = $inmax + $in
                $outmax = $outmax + $out
                $inP = Round((($inmax / 1024) / 1024), 2)
                $outP = Round((($outmax / 1024) / 1024), 2)
                $intext = "Bytes In/Sec: " & int($in) & " [" &$inP & " MB]" & @CRLF
                $outtext = "Bytes Out/Sec: " & int($out) & " [" &$outP & " MB]" &@CRLF

                GUICtrlSetData ($label1,$intext)
                GUICtrlSetData ($label2,$outtext)
                
            EndIf
            
            ExitLoop ; I only care about the first network adapter, yo
        Next
    EndIf
   sleep(1000) ; bytes PER SECOND
   If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop
   WEnd

Share this post


Link to post
Share on other sites
TDD

Since I cannot edit, i'll add on here, that from what I can work out of Win32_PerfRawData_Tcpip_NetworkInterface, it does not show the IP from the location, so is there another method for which to gather the IP of the connection?

EDIT: I don't know of how much relevance it is, but would the "AddressMask" from the "Win32_PerfFormattedData_Tcpip_ICMP" be what I'm looking for? If so, how could that be included into this project to work?

Edited by TDD

Share this post


Link to post
Share on other sites
playlet

---

Edited by playlet

Share this post


Link to post
Share on other sites
TDD

Thankyou for the help playlet, but that script you posted doesn't work, and i've tried to get it to work with no avail, it just sits at "Status: Connected" and never increments on anything, same goes with the time connected even... :S

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×