Didonet Posted November 30, 2007 Share Posted November 30, 2007 Hi It's me again, with my dump questions And here is the question.. how to get the current outgoing and incoming traffic? And the all send and recieved bytes from the local area connection. I think i must call some dlls for this, but... idk... Link to comment Share on other sites More sharing options...
weaponx Posted November 30, 2007 Share Posted November 30, 2007 You can do it with WMI, there are examples of this.http://www.autoitscript.com/forum/index.ph...twork++activity Link to comment Share on other sites More sharing options...
Didonet Posted November 30, 2007 Author Share Posted November 30, 2007 Thanks again, @weaponx! Maybe I'll create a networ monitor and show the stats with graphics Link to comment Share on other sites More sharing options...
Didonet Posted November 30, 2007 Author Share Posted November 30, 2007 nah.. I can't create this thing ;( Can u help me? I want to create this... Link to comment Share on other sites More sharing options...
Sardith Posted December 1, 2007 Share Posted December 1, 2007 Take a look at this:Graph example -weaponx [font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font] Link to comment Share on other sites More sharing options...
Didonet Posted December 1, 2007 Author Share Posted December 1, 2007 Thanks, but I don't know how to control the graph... (blush) I create it with the function GraphX(), but how to change the position of the line? Link to comment Share on other sites More sharing options...
Didonet Posted December 1, 2007 Author Share Posted December 1, 2007 up Link to comment Share on other sites More sharing options...
weaponx Posted December 1, 2007 Share Posted December 1, 2007 (edited) The way my graph function works by default is by recording all the data into an array over a preset period of time, then displaying it. It will not show in real time without some modification. I'll try to have something for you by tomorrow. Edited December 1, 2007 by weaponx Link to comment Share on other sites More sharing options...
Didonet Posted December 1, 2007 Author Share Posted December 1, 2007 Thanks! Link to comment Share on other sites More sharing options...
Didonet Posted December 2, 2007 Author Share Posted December 2, 2007 Link to comment Share on other sites More sharing options...
weaponx Posted December 3, 2007 Share Posted December 3, 2007 Well i'm kind of stuck. The graph works great in real time, it will run for 60 second increments. Only problem is getting the proper data from WMI for bytes sent / received. It keeps returning garbage values. You can see the lines I have commented out that will switch from random to real data. expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.8.1 Author: WeaponX Script Function: Steam style graph generator #ce ---------------------------------------------------------------------------- #include <GUIConstants.au3> GraphX() ;GraphX Func GraphX($graphTitle = "") ;Define colors Local $graphBGColor = 0x242529 Local $graphBorderColor = 0x000000 Local $graphLabelColor = 0x787878 Local $graphWidth = 400 Local $graphHeight = 100 Local $graphLineColor1 = 0xc98d35 Local $graphLineColor2 = 0x686868 Local $graphGridXInterval = 4 Local $graphGridYInterval = 4 $graphSumLine1 = 0 $graphSumLine2 = 0 Local $graphMinX = 0 Local $graphMaxX = 60 Local $graphMinY = 0 Local $graphMaxY = 1000 ;kB/s ;Create Main window GUICreate("Graph X: " & $graphTitle, 500, 200, -1) GUISetState (@SW_SHOW) GUISetBkColor (0x424242) ;Define Y labels (% cpu usage) GUICtrlCreateLabel ($graphMaxY & " kB/s", 3, 3, 60, 20, $SS_RIGHT) GUICtrlSetColor ( -1, $graphLabelColor) GUICtrlSetFont (-1,8, 600) GUICtrlCreateLabel ($graphMaxY / 2 & " kB/s",3, 50, 60,20, $SS_RIGHT) GUICtrlSetColor ( -1, $graphLabelColor) GUICtrlSetFont (-1,8, 600) GUICtrlCreateLabel ("0 kB/s", 3, 95, 60,20, $SS_RIGHT) GUICtrlSetColor ( -1, $graphLabelColor) GUICtrlSetFont (-1,8, 600) ;Define X labels (elapsed time) GUICtrlCreateLabel ($graphMinX & " s", 70, 107, 20) GUICtrlSetColor ( -1, $graphLabelColor) GUICtrlSetFont (-1,8, 600) GUICtrlCreateLabel (($graphMaxX + $graphMinX) / 2 & " s", 260, 107, 30) GUICtrlSetColor ( -1, $graphLabelColor) GUICtrlSetFont (-1,8, 600) GUICtrlCreateLabel ($graphMaxX & " s", 460, 107, 30) GUICtrlSetColor ( -1, $graphLabelColor) GUICtrlSetFont (-1,8, 600) ;Draw average Line 1 GUICtrlCreateLabel ("Avg speed Sent:", 10, 140, 190) GUICtrlSetColor ( -1, $graphLabelColor) GUICtrlSetFont (-1,12, 700) $avgLine1 = GUICtrlCreateLabel (StringFormat("%.2f", $graphSumLine1 / $graphMaxX) & " kB/s", 200, 140, 170) GUICtrlSetColor ( -1, $graphLineColor1) GUICtrlSetFont (-1,12, 700) ;Draw average Line 2 GUICtrlCreateLabel ("Avg speed Received:", 10, 160, 170) GUICtrlSetColor ( -1, $graphLabelColor) GUICtrlSetFont (-1,12, 700) $avgLine2 = GUICtrlCreateLabel (StringFormat("%.2f", $graphSumLine2 / $graphMaxX) & " kB/s", 200, 160, 170) GUICtrlSetColor ( -1, $graphLineColor2) GUICtrlSetFont (-1,12, 700) While 1 ;Create the graphic "sandbox" area $graphic = GuiCtrlCreateGraphic(70, 5, $graphWidth,$graphHeight) GUICtrlSetBkColor(-1,$graphBGColor) GUICtrlSetColor (-1, $graphBorderColor) ;Draw grid lines at specified interval (skip first and last): Y For $X = 1 to $graphGridYInterval - 1 GUICtrlSetGraphic(-1,$GUI_GR_MOVE, 0,$graphHeight * ($X / $graphGridYInterval)) GUICtrlSetGraphic(-1,$GUI_GR_LINE,$graphWidth, $graphHeight * ($X / $graphGridYInterval)) Next ;Draw grid lines at specified interval (skip first and last): X For $X = 1 to $graphGridXInterval - 1 GUICtrlSetGraphic(-1,$GUI_GR_MOVE, $graphWidth * ($X / $graphGridXInterval),0) GUICtrlSetGraphic(-1,$GUI_GR_LINE,$graphWidth * ($X / $graphGridXInterval), $graphHeight) Next $Line1LastX = 0 $Line1LastY = $graphHeight $Line2LastX = 0 $Line2LastY = $graphHeight For $X = 1 to $graphMaxX ;Retrieve current bytes sent / received per second $RxTx = RetrieveTraffic() TrayTip("Network Activity", "Rx :" & $RxTx[0] & " kB/s" & @CRLF & "Tx :" & $RxTx[1] & " kB/s", 5) ;Set line color GUICtrlSetGraphic(-1,$GUI_GR_COLOR, $graphLineColor1) ;Define starting point GUICtrlSetGraphic(-1,$GUI_GR_MOVE, $Line1LastX,$Line1LastY) ;Draw line 1 ;------------------------------------------ ;Convert input value (relative %) into absolute pixel value $tempX = ($graphWidth / $graphMaxX) * $X $random = Random(0,1000,1) ;Reflect Y value $tempY = $graphHeight - (($graphHeight / $graphMaxY) * $random) ;$tempY = $graphHeight - (($graphHeight / $graphMaxY) * $RxTx[0]) GUICtrlSetGraphic(-1,$GUI_GR_LINE,$tempX,$tempY) GUICtrlSetGraphic(-1,$GUI_GR_REFRESH) $graphSumLine1 += $random ;$graphSumLine1 += $RxTx[0] $Line1LastX = $tempX $Line1LastY = $tempY ;Set line color GUICtrlSetGraphic(-1,$GUI_GR_COLOR, $graphLineColor2) ;Define starting point GUICtrlSetGraphic(-1,$GUI_GR_MOVE, $Line2LastX,$Line2LastY) ;Draw line 2 ;------------------------------------------ ;Convert input value (relative %) into absolute pixel value $tempX = ($graphWidth / $graphMaxX) * $X $random = Random(0,1000,1) ;Reflect Y value $tempY = $graphHeight - (($graphHeight / $graphMaxY) * $random) ;$tempY = $graphHeight - (($graphHeight / $graphMaxY) * $RxTx[1]) GUICtrlSetGraphic(-1,$GUI_GR_LINE,$tempX,$tempY) GUICtrlSetGraphic(-1,$GUI_GR_REFRESH) $graphSumLine2 += $random ;$graphSumLine2 += $RxTx[1] $Line2LastX = $tempX $Line2LastY = $tempY GuiCtrlSetData($avgLine1,StringFormat("%.2f", $graphSumLine1 / $X) & " kB/s") GuiCtrlSetData($avgLine2,StringFormat("%.2f", $graphSumLine2 / $X) & " kB/s") ;Refresh every second Sleep(1000) Next GUICtrlDelete($graphic) WEnd Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE EndFunc ;Retrieve network activity in kilobytes ;[0]: Sent ;[1]: Received Func RetrieveTraffic() Local $RxTx[2] $colItems = "" $strComputer = "localhost" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") ;$colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec FROM Win32_PerfFormattedData_Tcpip_NetworkInterface", "WQL", 0x10 + 0x20) $colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", 0x10 + 0x20) If IsObj($colItems) then For $objItem In $colItems $in = $objItem.BytesReceivedPersec $out = $objItem.BytesSentPersec $in = Int($in/1024) $out = Int($out/1024) ;MsgBox(0,"","in: " & $in & @CRLF & "out: " & $out) $RxTx[0] = $in $RxTx[1] = $out Return $RxTx Next EndIf EndFunc 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