SoulA Posted November 17, 2008 Share Posted November 17, 2008 (edited) I tried to improve upon Lod3n's bandwidth monitor and have it support more than one interface. EDIT: put up a nicer version combining aceguy's code and some other stuff. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $aLabel = _GetNames(_GetObj()) Dim $aCheckBox[$aLabel[0] + 1][2] Dim $aAdapter[2] $hSelection = GUICreate("Selection", 300, $aLabel[0] * 30 + 30, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE)) If $aLabel[0] = 0 Then MsgBox(0, "Error", "No Adapters Found", 0, $hSelection) Exit EndIf For $i = 1 To $aLabel[0] $aCheckBox[$i][0] = GUICtrlCreateCheckbox($aLabel[$i], 8, $i * 20, 290) $aCheckBox[$i][1] = $aLabel[$i] Next $aCheckBox[0][0] = $aLabel[0] $Button1 = GUICtrlCreateButton("okay", 100, $aLabel[0] * 30, 75) GUISetState(@SW_SHOW) While 1 Sleep(50) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $i1 = 1 $bExit = 0 For $i = 1 To $aCheckBox[0][0] If GUICtrlRead($aCheckBox[$i][0]) = 1 Then $aAdapter[0] = $i1 ReDim $aAdapter[$i1 + 1] $aAdapter[$i1] = $aCheckBox[$i][1] $i1 += 1 $bExit = 1 EndIf Next If $bExit = 1 Then GUIDelete($hSelection) ExitLoop Else MsgBox(0, "Error", "No Adapter Selected", 0, $hSelection) EndIf EndSwitch WEnd Opt("GUIOnEventMode", 1) $hMonitor = GUICreate("Monitor", 150, 100, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE)) GUISetFont(12) $Label1 = GUICtrlCreateLabel("", 8, 8, 100, 24) $Label2 = GUICtrlCreateLabel("", 8, 23, 100, 24) $Label3 = GUICtrlCreateLabel("", 8, 38, 100, 24) $Label4 = GUICtrlCreateLabel("", 8, 53, 100, 24) $label5 = GUICtrlCreateLabel("", 8, 68, 100, 24) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState(@SW_SHOW) $Data_now = _GetData(_GetObj(), $aAdapter) GUICtrlSetData($Label5, Round($Data_now[0] / 073741824, 2) & "Total GB") While 1 $btmp= _GetData(_GetObj(), $aAdapter) Sleep(1000) $aData = _GetData(_GetObj(), $aAdapter) $bData = $aData[0] - $Data_now[0] $difftmp= ($aData[0]-$btmp[0]) GUICtrlSetData($Label1, Round($difftmp, 2) & " Diff") GUICtrlSetData($Label2, Round($bData / 1024, 2) & " KB") GUICtrlSetData($Label3, Round($bData / 1048576, 2) & " MB") GUICtrlSetData($Label4, Round($bData / 073741824, 2) & " GB") WEnd Func _GetNames($colItems) Local $aName[2], $i = 1 If IsObj($colItems) Then For $objItem In $colItems $aName[0] = $i ReDim $aName[$i + 1] $aName[$i] = $objItem.Name $i += 1 Next EndIf Return $aName EndFunc ;==>_GetNames Func _GetData($colItems, $aAdapter) Local $aData[2] If IsObj($colItems) Then For $objItem In $colItems For $i = 1 To $aAdapter[0] If $objItem.Name = $aAdapter[$i] Then $aData[0] += $objItem.BytesReceivedPersec $aData[1] += $objItem.BytesSentPersec EndIf Next Next EndIf Return $aData EndFunc ;==>_GetData Func _GetObj() Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20, $colItems = "", $strComputer = "localhost" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec,Name FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) Return $colItems EndFunc ;==>_GetObj Func _Exit() Exit EndFunc Edited November 19, 2008 by SoulA Link to comment Share on other sites More sharing options...
Achilles Posted November 17, 2008 Share Posted November 17, 2008 The numbers seem to work great.. But could display it in kilobytes? I would actually do something like this: Gigabytes: 0 Megabytes:12 Kilobytess:500 Bytes:40 And as soon as there are 1024 kilobytes, it goes up megabyte and resets the kilobyte label to 0, same for megabytes to gigabytes and bytes to kilobytes.. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
SoulA Posted November 17, 2008 Author Share Posted November 17, 2008 I'll take a look and try to add this functionality. I also made some changes making the code a little more efficient. Link to comment Share on other sites More sharing options...
Aceguy Posted November 18, 2008 Share Posted November 18, 2008 (edited) SWEET Prog. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $aLabel = _GetNames(_GetObj()) Dim $aCheckBox[$aLabel[0] + 1][2] Dim $aAdapter[2] $hSelection = GUICreate("Selection", 300, $aLabel[0] * 45, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE)) If $aLabel[0] = 0 Then MsgBox(0, "Error", "No Adapters Found", 0, $hSelection) Exit EndIf For $i = 1 To $aLabel[0] $aCheckBox[$i][0] = GUICtrlCreateCheckbox($aLabel[$i], 8, $i * 20, 290) $aCheckBox[$i][1] = $aLabel[$i] Next $aCheckBox[0][0] = $aLabel[0] $Button1 = GUICtrlCreateButton("okay", 100, $aLabel[0] * 30, 75) GUISetState(@SW_SHOW) While 1 Sleep(50) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $i1 = 1 $bExit = 0 For $i = 1 To $aCheckBox[0][0] If GUICtrlRead($aCheckBox[$i][0]) = 1 Then $aAdapter[0] = $i1 ReDim $aAdapter[$i1 + 1] $aAdapter[$i1] = $aCheckBox[$i][1] $i1 += 1 $bExit = 1 EndIf Next If $bExit = 1 Then GUIDelete($hSelection) ExitLoop Else MsgBox(0, "Error", "No Adapter Selected", 0, $hSelection) EndIf EndSwitch WEnd $hMonitor = GUICreate("Monitor", 212, 118, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE)) GUISetFont(12) $Label1 = GUICtrlCreateLabel("", 8, 8, 100, 24) $Label2 = GUICtrlCreateLabel("", 8, 23, 100, 24) $Label3 = GUICtrlCreateLabel("", 8, 38, 100, 24) $Label4 = GUICtrlCreateLabel("", 8, 53, 100, 24) GUISetState(@SW_SHOW) $Data_now = _GetData(_GetObj(), $aAdapter) ConsoleWrite($Data_now[0]) While 1 $btmp= _GetData(_GetObj(), $aAdapter) Sleep(1000) If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit $aData = _GetData(_GetObj(), $aAdapter) $bData = $aData[0] - $Data_now[0] $difftmp= ($aData[0]-$btmp[0]) GUICtrlSetData($Label1, Round($difftmp, 2) & " Diff") GUICtrlSetData($Label2, Round($bData / 1024, 2) & " KB") GUICtrlSetData($Label3, Round($bData / 1048576, 2) & " MB") GUICtrlSetData($Label4, Round($bData / 073741824, 2) & " GB") WEnd Func _GetNames($colItems) Local $aName[2], $i = 1 If IsObj($colItems) Then For $objItem In $colItems $aName[0] = $i ReDim $aName[$i + 1] $aName[$i] = $objItem.Name $i += 1 Next EndIf Return $aName EndFunc ;==>_GetNames Func _GetData($colItems, $aAdapter) Local $aData[2] If IsObj($colItems) Then For $objItem In $colItems For $i = 1 To $aAdapter[0] If $objItem.Name = $aAdapter[$i] Then $aData[0] += $objItem.BytesReceivedPersec $aData[1] += $objItem.BytesSentPersec EndIf Next Next EndIf Return $aData EndFunc ;==>_GetData Func _GetObj() Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20, $colItems = "", $strComputer = "localhost" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec,Name FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) Return $colItems EndFunc ;==>_GetObj Edited November 18, 2008 by Aceguy [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
SoulA Posted November 18, 2008 Author Share Posted November 18, 2008 COOL! One more change I would make is turning on event mode for the second part of GUI since the sleep in the while loop is so long. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $aLabel = _GetNames(_GetObj()) Dim $aCheckBox[$aLabel[0] + 1][2] Dim $aAdapter[2] $hSelection = GUICreate("Selection", 300, $aLabel[0] * 45, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE)) If $aLabel[0] = 0 Then MsgBox(0, "Error", "No Adapters Found", 0, $hSelection) Exit EndIf For $i = 1 To $aLabel[0] $aCheckBox[$i][0] = GUICtrlCreateCheckbox($aLabel[$i], 8, $i * 20, 290) $aCheckBox[$i][1] = $aLabel[$i] Next $aCheckBox[0][0] = $aLabel[0] $Button1 = GUICtrlCreateButton("okay", 100, $aLabel[0] * 30, 75) GUISetState(@SW_SHOW) While 1 Sleep(50) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $i1 = 1 $bExit = 0 For $i = 1 To $aCheckBox[0][0] If GUICtrlRead($aCheckBox[$i][0]) = 1 Then $aAdapter[0] = $i1 ReDim $aAdapter[$i1 + 1] $aAdapter[$i1] = $aCheckBox[$i][1] $i1 += 1 $bExit = 1 EndIf Next If $bExit = 1 Then GUIDelete($hSelection) ExitLoop Else MsgBox(0, "Error", "No Adapter Selected", 0, $hSelection) EndIf EndSwitch WEnd Opt("GUIOnEventMode", 1) $hMonitor = GUICreate("Monitor", 212, 118, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE)) GUISetFont(12) $Label1 = GUICtrlCreateLabel("", 8, 8, 100, 24) $Label2 = GUICtrlCreateLabel("", 8, 23, 100, 24) $Label3 = GUICtrlCreateLabel("", 8, 38, 100, 24) $Label4 = GUICtrlCreateLabel("", 8, 53, 100, 24) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState(@SW_SHOW) $Data_now = _GetData(_GetObj(), $aAdapter) While 1 $btmp= _GetData(_GetObj(), $aAdapter) Sleep(1000) $aData = _GetData(_GetObj(), $aAdapter) $bData = $aData[0] - $Data_now[0] $difftmp= ($aData[0]-$btmp[0]) GUICtrlSetData($Label1, Round($difftmp, 2) & " Diff") GUICtrlSetData($Label2, Round($bData / 1024, 2) & " KB") GUICtrlSetData($Label3, Round($bData / 1048576, 2) & " MB") GUICtrlSetData($Label4, Round($bData / 073741824, 2) & " GB") WEnd Func _GetNames($colItems) Local $aName[2], $i = 1 If IsObj($colItems) Then For $objItem In $colItems $aName[0] = $i ReDim $aName[$i + 1] $aName[$i] = $objItem.Name $i += 1 Next EndIf Return $aName EndFunc ;==>_GetNames Func _GetData($colItems, $aAdapter) Local $aData[2] If IsObj($colItems) Then For $objItem In $colItems For $i = 1 To $aAdapter[0] If $objItem.Name = $aAdapter[$i] Then $aData[0] += $objItem.BytesReceivedPersec $aData[1] += $objItem.BytesSentPersec EndIf Next Next EndIf Return $aData EndFunc ;==>_GetData Func _GetObj() Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20, $colItems = "", $strComputer = "localhost" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec,Name FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) Return $colItems EndFunc ;==>_GetObj Func _Exit() Exit EndFunc Link to comment Share on other sites More sharing options...
billthecreator Posted November 19, 2008 Share Posted November 19, 2008 (edited) hey, cool. im using this for my school. im only allowed 4 gb of bandwidth a week, this will help greatly. ive changed it a little. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> $aLabel = _GetNames(_GetObj()) Dim $aCheckBox[$aLabel[0] + 1][2] Dim $aAdapter[2] $hSelection = GUICreate("Selection", 300, $aLabel[0] * 45, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE)) If $aLabel[0] = 0 Then MsgBox(0, "Error", "No Adapters Found", 0) Exit EndIf For $i = 1 to $aLabel[0] $aCheckBox[$i][0] = GUICtrlCreateCheckbox($aLabel[$i], 8, $i * 20, 290) GUICtrlSetState(-1, $GUI_CHECKED) $aCheckBox[$i][1] = $aLabel[$i] Next $aCheckBox[0][0] = $aLabel[0] $Button1 = GUICtrlCreateButton("Okay", 100, $aLabel[0] * 30, 75) GUISetState(@SW_SHOW) While 1 Sleep(50) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $i1 = 1 $bExit = 0 For $i = 1 to $aCheckBox[0][0] If GUICtrlRead($aCheckBox[$i][0]) = 1 Then $aAdapter[0] = $i1 ReDim $aAdapter[$i1 + 1] $aAdapter[$i1] = $aCheckBox[$i][1] $i1 += 1 $bExit = 1 EndIf Next If $bExit = 1 Then GUIDelete($hSelection) ExitLoop Else MsgBox(0, "Error", "No Adapter Selected", 0) EndIf EndSwitch WEnd $Tenth = 20 $hMonitor = GUICreate("Monitor", 212, 100, -1, -1) GUISetFont(9) $Menu = GUICtrlCreateMenu("&Options") $bytesize = GUICtrlCreateMenu("Byte Size", $Menu) $kbyte = GUICtrlCreateMenuItem("KB", $bytesize) $mbyte = GUICtrlCreateMenuItem("MB", $bytesize) GUICtrlSetState(-1, $GUI_CHECKED) $gbyte = GUICtrlCreateMenuItem("GB", $bytesize) $Label1 = GUICtrlCreateLabel("Bandwidth: Megabytes", 8, 8, 145, 24) $Label3 = GUICtrlCreateLabel("", 8, 32, 210, 24) $Label5 = GUICtrlCreateLabel("", 100, 32, 110, 20, $SS_RIGHT) $progress = GUICtrlCreateProgress(8, 56, 160, 15) $Label7 = GUICtrlCreateLabel("4 GB", 180, 55, 100, 24) GUISetState(@SW_SHOW) While 1 $Msg = GUIGetMsg() If $Msg = $GUI_EVENT_CLOSE Then Exit If $Msg = $kbyte Then GUICtrlSetState($kbyte, $GUI_CHECKED) GUICtrlSetState($mbyte, $GUI_UNCHECKED) GUICtrlSetState($gbyte, $GUI_UNCHECKED) $Tenth = 10 GUICtrlSetData($Label1, "Bandwidth: Kilobytes") ElseIf $Msg = $mbyte Then GUICtrlSetState($kbyte, $GUI_UNCHECKED) GUICtrlSetState($mbyte, $GUI_CHECKED) GUICtrlSetState($gbyte, $GUI_UNCHECKED) $Tenth = 20 GUICtrlSetData($Label1, "Bandwidth: Megabytes") ElseIf $Msg = $gbyte Then GUICtrlSetState($kbyte, $GUI_UNCHECKED) GUICtrlSetState($mbyte, $GUI_UNCHECKED) GUICtrlSetState($gbyte, $GUI_CHECKED) $Tenth = 30 GUICtrlSetData($Label1, "Bandwidth: Gigabytes") EndIf $aData = _GetData(_GetObj(), $aAdapter) $BYTE = Round( ($aData[0]) / (2 ^ $Tenth),4) GUICtrlSetData($Label3, $BYTE) GUICtrlSetData($progress, ($aData[0] / (4 * (2^30))) * 100) GUICtrlSetData($Label5, Round($aData[0] / (4 * (2^30)) * 100, 2) & "%") WEnd Func _GetNames($colItems) Local $aName[2], $i = 1 If IsObj($colItems) then For $objItem In $colItems $aName[0] = $i ReDim $aName[$i + 1] $aName[$i] = $objItem.Name $i += 1 Next EndIf Return $aName EndFunc Func _GetData($colItems, $aAdapter) Local $aData[2] If IsObj($colItems) then For $objItem In $colItems For $i = 1 to $aAdapter[0] If $objItem.Name = $aAdapter[$i] Then $aData[0] += $objItem.BytesReceivedPersec $aData[1] += $objItem.BytesSentPersec EndIf Next Next EndIf Return $aData EndFunc Func _GetObj() Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20, $colItems = "", $strComputer = "localhost" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec,Name FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) Return $colItems EndFunc do you think you can add like K/bs or something, i probably could figure it out. i just dont got the time right now. Edited November 19, 2008 by billthecreator [font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap Link to comment Share on other sites More sharing options...
Aceguy Posted November 19, 2008 Share Posted November 19, 2008 Superb scripts, wonder if there is a way for filter out NetTraffic From Lan Traffic. [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
BrettF Posted November 27, 2008 Share Posted November 27, 2008 Superb scripts, wonder if there is a way for filter out NetTraffic From Lan Traffic.I'd really like to know this.Any ideas???Cheers,Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now