Sign in to follow this  
Followers 0
Didonet

Get some traffic info

11 posts in this topic

Hi :P

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

Share this post


Link to post
Share on other sites



Thanks again, @weaponx! Maybe I'll create a networ monitor and show the stats with graphics :P

Share this post


Link to post
Share on other sites

nah.. I can't create this thing ;(

Can u help me? I want to create this...

post-26864-1196464782_thumb.png

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

up :)

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by weaponx

Share this post


Link to post
Share on other sites

Thanks! :)

Share this post


Link to post
Share on other sites
:)

Share this post


Link to post
Share on other sites

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.

#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

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  
Followers 0