#include <GuiConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
Opt("TrayMenuMode", 1)
Global $i_Timer
$hGUI = GUICreate("Интернет-активность", 300, 160, -1, -1)
GUICtrlCreateLabel("Статистика интернет-соединения", 0, 10, 300, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800, 4)
GUICtrlSetColor(-1, 0xFF0000)
_GUICtrlCreateGroupEx("Информация", 10, 40, 280, 100, 3, 0x0000FF, 1, 'netshell.dll', -12)
GUICtrlCreateLabel("Передано:", 20, 50, 150)
$Transmitted_Label = GUICtrlCreateLabel("", 200, 50, 90, 15)
GUICtrlCreateLabel("Получено:", 20, 70, 150)
$Received_Label = GUICtrlCreateLabel("", 200, 70, 90, 15)
GUICtrlCreateLabel("Сумма обмена:", 20, 90, 150)
$Total_Label = GUICtrlCreateLabel("", 200, 90, 90, 15)
GUICtrlCreateLabel("Продолжительность:", 20, 110, 150)
$Duration_Label = GUICtrlCreateLabel("", 200, 110, 90, 15)
For $i = $Transmitted_Label - 1 To $Duration_Label Step 2
GUICtrlSetFont($i, 8.5, 800)
Next
If Ping('google.com') Then
_Set_RasConnectionStatistics_Proc()
EndIf
$i_Timer = _Timer_SetTimer($hGUI, 1000, "_RCS_CallBack_Proc")
GUISetState(@SW_SHOW, $hGUI)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
_Timer_KillTimer($hGUI, $i_Timer)
Exit
EndSwitch
WEnd
Func _RCS_CallBack_Proc($hWnd, $Msg, $iIDTimer, $dwTime)
If Ping('google.com') Then
_Set_RasConnectionStatistics_Proc()
EndIf
EndFunc ;==>_RCS_CallBack_Proc
Func _Set_RasConnectionStatistics_Proc()
Local $aStatistics = _RasGetConnectionStatistics()
GUICtrlSetData($Transmitted_Label, _String_GetFormatedSize($aStatistics[0], 2, "MB"))
GUICtrlSetData($Received_Label, _String_GetFormatedSize($aStatistics[1], 2, "MB"))
GUICtrlSetData($Total_Label, _String_GetFormatedSize($aStatistics[2]))
GUICtrlSetData($Duration_Label, _SecondsToTimeString($aStatistics[3] / 1000))
EndFunc ;==>_Set_RasConnectionStatistics_Proc
; $iFlag:
; 1 - The number of bytes transmitted through this connection or link.
; 2 - The number of bytes received through this connection or link.
; 3 - Total
; 4 - The amount of time, in milliseconds, that the connection or link has been connected.
; -1 (default) - All above statistics data in array.
Func _RasGetConnectionStatistics($sFlags = -1)
Local Const $MAX_PATH = 260
Local Const $RAS_MaxDeviceType = 16
Local Const $RAS_MaxEntryName = 256
Local Const $RAS_MaxDeviceName = 128
$tRASCONN = DllStructCreate("dword dwSize;hwnd hRasConn;char szEntryName[" & $RAS_MaxEntryName + 1 & "];" & _
"char szDeviceType[" & $RAS_MaxDeviceType + 1 & "];" & _
"char szDeviceName[" & $RAS_MaxDeviceName + 1 & "];" & _
"char szPhonebook[" & $MAX_PATH & "];" & _
"dword dwSubEntry;byte guidEntry[16];dword dwFlags;byte luid[8]")
$tRAS_STATS = DllStructCreate("dword dwSize;dword dwBytesXmited;dword dwBytesRcved;dword dwFramesXmited;" & _
"dword dwFramesRcved;dword dwCrcErr;dword dwTimeoutErr;dword dwAlignmentErr;" & _
"dword dwHardwareOverrunErr;dword dwFramingErr;dword dwBufferOverrunErr;" & _
"dword dwCompressionRatioIn;dword dwCompressionRatioOut;dword dwBps;dword dwConnectDuration")
$iCntByte = DllStructCreate("dword")
$iCntConn = DllStructCreate("dword")
DllStructSetData($iCntByte, 1, DllStructGetSize($tRASCONN))
DllStructSetData($tRASCONN, "dwSize", DllStructGetSize($tRASCONN))
DllStructSetData($tRAS_STATS, "dwSize", DllStructGetSize($tRAS_STATS))
$aRet = DllCall("rasapi32.dll", "int", "RasEnumConnections", _
"ptr", DllStructGetPtr($tRASCONN), _
"ptr", DllStructGetPtr($iCntByte), _
"ptr", DllStructGetPtr($iCntConn))
If $aRet[0] Then Return SetError(2, $aRet[0], -1)
If DllStructGetData($iCntConn, 1) < 1 Then Return SetError(1, 0, 0) ;Error: not opened connections
$aRet = DllCall("rasapi32.dll", "int", "RasGetConnectionStatistics", _
"hwnd", DllStructGetData($tRASCONN, "hRasConn"), _
"ptr", DllStructGetPtr($tRAS_STATS))
If $aRet[0] Then Return SetError(3, $aRet[0], -1)
Local $iResult[4] = _
[ _
DllStructGetData($tRAS_STATS, "dwBytesXmited"), _
DllStructGetData($tRAS_STATS, "dwBytesRcved"), _
DllStructGetData($tRAS_STATS, "dwBytesXmited") + DllStructGetData($tRAS_STATS, "dwBytesRcved"), _
DllStructGetData($tRAS_STATS, "dwConnectDuration") _
]
Switch $sFlags
Case 1
Return $iResult[0]
Case 2
Return $iResult[1]
Case 3
Return $iResult[2]
Case 4
Return $iResult[3]
Case -1, Default
Return $iResult
EndSwitch
Return 0
EndFunc ;==>_RasGetConnectionStatistics
Func _SecondsToTimeString($iSeconds, $sDelim = ":", $iFlag = 1)
If Number($iSeconds) >= 0 Then
Local $iTicks = Int($iSeconds / 3600), $iDays, $iYears
Local $iHours = Mod($iTicks, 24)
If $iTicks >= 24 Then $iDays = ($iTicks - $iHours) / 24
If $iDays >= 365 Then $iYears = Int($iDays / 365) & " Year(s), "
If $iDays > 0 Then $iDays = Mod($iDays, 365) & " Day(s), "
$iTicks = Mod($iSeconds, 3600)
Local $iMins = Int($iTicks / 60)
Local $iSecs = Round(Mod($iTicks, 60))
If $iFlag = 1 Then
If StringLen($iHours) = 1 Then $iHours = "0" & $iHours
If StringLen($iMins) = 1 Then $iMins = "0" & $iMins
If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs
EndIf
Return $iYears & $iDays & $iHours & $sDelim & $iMins & $sDelim & $iSecs
EndIf
Return SetError(1, 0, 0)
EndFunc ;==>_SecondsToTimeString
Func _String_GetFormatedSize($iByteSize, $iRound = 2, $sRetFormat = -1)
Local $asBytes[9] = [8, 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] ;Last two unreachable
Local $iBytes_Val = 2 ^ 10
If $iByteSize < $iBytes_Val Then Return $iByteSize & ' Bytes'
If IsString($sRetFormat) Then
For $i = 1 To 8
If $sRetFormat = $asBytes[$i] Then Return Round($iByteSize / $iBytes_Val ^ $i, $iRound) & ' ' & $asBytes[$i]
Next
Else
For $i = 8 To 1 Step -1
If $iByteSize >= $iBytes_Val ^ $i Then Return Round($iByteSize / $iBytes_Val ^ $i, $iRound) & ' ' & $asBytes[$i]
Next
EndIf
EndFunc ;==>_String_GetFormatedSize
Func _GUICtrlCreateGroupEx($sText, $iLeft, $iTop, $iWidth, $iHeight, $iLineWidth = 3, $nColor = 0, $iStyle = 0, $sIcon = '', $nIconID = 0)
Local $aIDs[2] ;First + Last IDs
Local $nLabel_Style = $SS_ETCHEDFRAME
;1 to able set color for the Group frame
If $iStyle > 0 Then $nLabel_Style = $SS_SUNKEN
GUIStartGroup()
$aIDs[0] = GUICtrlCreateLabel('', $iLeft + 1, $iTop, $iWidth - 2, $iLineWidth, $nLabel_Style)
GUICtrlSetBkColor(-1, $nColor)
GUICtrlCreateLabel('', $iLeft + 2, $iTop + 5, $iLineWidth, $iHeight - 4, $nLabel_Style)
GUICtrlSetBkColor(-1, $nColor)
GUICtrlCreateLabel('', ($iLeft + $iWidth), $iTop - 3, $iLineWidth, $iHeight - 3, $nLabel_Style)
GUICtrlSetBkColor(-1, $nColor)
$aIDs[1] = GUICtrlCreateLabel('', $iLeft + 6, ($iTop + $iHeight) - 5, $iWidth, $iLineWidth, $nLabel_Style)
GUICtrlSetBkColor(-1, $nColor)
If $sText <> '' Then
If $sIcon <> '' Then
$iLeft += 15
$sText = ' ' & $sText
EndIf
$aIDs[1] = GUICtrlCreateLabel(' ' & $sText, $iLeft + 35, $iTop - 6)
GUICtrlSetColor(-1, $nColor)
EndIf
If $sIcon <> '' Then GUICtrlCreateIcon($sIcon, $nIconID, $iLeft + 25, $iTop - 8, 16, 16)
Return $aIDs
EndFunc ;==>_GUICtrlCreateGroupEx
#include <GuiConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
Opt("TrayMenuMode", 1)
Global $i_Timer
$hGUI = GUICreate("Интернет-активность", 300, 160, -1, -1)
GUICtrlCreateLabel("Статистика интернет-соединения", 0, 10, 300, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800, 4)
GUICtrlSetColor(-1, 0xFF0000)
_GUICtrlCreateGroupEx("Информация", 10, 40, 280, 100, 3, 0x0000FF, 1, 'netshell.dll', -12)
GUICtrlCreateLabel("Передано:", 20, 50, 150)
$Transmitted_Label = GUICtrlCreateLabel("", 200, 50, 90, 15)
GUICtrlCreateLabel("Получено:", 20, 70, 150)
$Received_Label = GUICtrlCreateLabel("", 200, 70, 90, 15)
GUICtrlCreateLabel("Сумма обмена:", 20, 90, 150)
$Total_Label = GUICtrlCreateLabel("", 200, 90, 90, 15)
GUICtrlCreateLabel("Продолжительность:", 20, 110, 150)
$Duration_Label = GUICtrlCreateLabel("", 200, 110, 90, 15)
For $i = $Transmitted_Label - 1 To $Duration_Label Step 2
GUICtrlSetFont($i, 8.5, 800)
Next
If Ping('google.com') Then
_Set_RasConnectionStatistics_Proc()
EndIf
$i_Timer = _Timer_SetTimer($hGUI, 1000, "_RCS_CallBack_Proc")
GUISetState(@SW_SHOW, $hGUI)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
_Timer_KillTimer($hGUI, $i_Timer)
Exit
EndSwitch
WEnd
Func _RCS_CallBack_Proc($hWnd, $Msg, $iIDTimer, $dwTime)
If Ping('google.com') Then
_Set_RasConnectionStatistics_Proc()
EndIf
EndFunc ;==>_RCS_CallBack_Proc
Func _Set_RasConnectionStatistics_Proc()
Local $aStatistics = _RasGetConnectionStatistics()
GUICtrlSetData($Transmitted_Label, _String_GetFormatedSize($aStatistics[0], 2, "MB"))
GUICtrlSetData($Received_Label, _String_GetFormatedSize($aStatistics[1], 2, "MB"))
GUICtrlSetData($Total_Label, _String_GetFormatedSize($aStatistics[2]))
GUICtrlSetData($Duration_Label, _SecondsToTimeString($aStatistics[3] / 1000))
EndFunc ;==>_Set_RasConnectionStatistics_Proc
; $iFlag:
; 1 - The number of bytes transmitted through this connection or link.
; 2 - The number of bytes received through this connection or link.
; 3 - Total
; 4 - The amount of time, in milliseconds, that the connection or link has been connected.
; -1 (default) - All above statistics data in array.
Func _RasGetConnectionStatistics($sFlags = -1)
Local Const $MAX_PATH = 260
Local Const $RAS_MaxDeviceType = 16
Local Const $RAS_MaxEntryName = 256
Local Const $RAS_MaxDeviceName = 128
$tRASCONN = DllStructCreate("dword dwSize;hwnd hRasConn;char szEntryName[" & $RAS_MaxEntryName + 1 & "];" & _
"char szDeviceType[" & $RAS_MaxDeviceType + 1 & "];" & _
"char szDeviceName[" & $RAS_MaxDeviceName + 1 & "];" & _
"char szPhonebook[" & $MAX_PATH & "];" & _
"dword dwSubEntry;byte guidEntry[16];dword dwFlags;byte luid[8]")
$tRAS_STATS = DllStructCreate("dword dwSize;dword dwBytesXmited;dword dwBytesRcved;dword dwFramesXmited;" & _
"dword dwFramesRcved;dword dwCrcErr;dword dwTimeoutErr;dword dwAlignmentErr;" & _
"dword dwHardwareOverrunErr;dword dwFramingErr;dword dwBufferOverrunErr;" & _
"dword dwCompressionRatioIn;dword dwCompressionRatioOut;dword dwBps;dword dwConnectDuration")
$iCntByte = DllStructCreate("dword")
$iCntConn = DllStructCreate("dword")
DllStructSetData($iCntByte, 1, DllStructGetSize($tRASCONN))
DllStructSetData($tRASCONN, "dwSize", DllStructGetSize($tRASCONN))
DllStructSetData($tRAS_STATS, "dwSize", DllStructGetSize($tRAS_STATS))
$aRet = DllCall("rasapi32.dll", "int", "RasEnumConnections", _
"ptr", DllStructGetPtr($tRASCONN), _
"ptr", DllStructGetPtr($iCntByte), _
"ptr", DllStructGetPtr($iCntConn))
If $aRet[0] Then Return SetError(2, $aRet[0], -1)
If DllStructGetData($iCntConn, 1) < 1 Then Return SetError(1, 0, 0) ;Error: not opened connections
$aRet = DllCall("rasapi32.dll", "int", "RasGetConnectionStatistics", _
"hwnd", DllStructGetData($tRASCONN, "hRasConn"), _
"ptr", DllStructGetPtr($tRAS_STATS))
If $aRet[0] Then Return SetError(3, $aRet[0], -1)
Local $iResult[4] = _
[ _
DllStructGetData($tRAS_STATS, "dwBytesXmited"), _
DllStructGetData($tRAS_STATS, "dwBytesRcved"), _
DllStructGetData($tRAS_STATS, "dwBytesXmited") + DllStructGetData($tRAS_STATS, "dwBytesRcved"), _
DllStructGetData($tRAS_STATS, "dwConnectDuration") _
]
Switch $sFlags
Case 1
Return $iResult[0]
Case 2
Return $iResult[1]
Case 3
Return $iResult[2]
Case 4
Return $iResult[3]
Case -1, Default
Return $iResult
EndSwitch
Return 0
EndFunc ;==>_RasGetConnectionStatistics
Func _SecondsToTimeString($iSeconds, $sDelim = ":", $iFlag = 1)
If Number($iSeconds) >= 0 Then
Local $iTicks = Int($iSeconds / 3600), $iDays, $iYears
Local $iHours = Mod($iTicks, 24)
If $iTicks >= 24 Then $iDays = ($iTicks - $iHours) / 24
If $iDays >= 365 Then $iYears = Int($iDays / 365) & " Year(s), "
If $iDays > 0 Then $iDays = Mod($iDays, 365) & " Day(s), "
$iTicks = Mod($iSeconds, 3600)
Local $iMins = Int($iTicks / 60)
Local $iSecs = Round(Mod($iTicks, 60))
If $iFlag = 1 Then
If StringLen($iHours) = 1 Then $iHours = "0" & $iHours
If StringLen($iMins) = 1 Then $iMins = "0" & $iMins
If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs
EndIf
Return $iYears & $iDays & $iHours & $sDelim & $iMins & $sDelim & $iSecs
EndIf
Return SetError(1, 0, 0)
EndFunc ;==>_SecondsToTimeString
Func _String_GetFormatedSize($iByteSize, $iRound = 2, $sRetFormat = -1)
Local $asBytes[9] = [8, 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] ;Last two unreachable
Local $iBytes_Val = 2 ^ 10
If $iByteSize < $iBytes_Val Then Return $iByteSize & ' Bytes'
If IsString($sRetFormat) Then
For $i = 1 To 8
If $sRetFormat = $asBytes[$i] Then Return Round($iByteSize / $iBytes_Val ^ $i, $iRound) & ' ' & $asBytes[$i]
Next
Else
For $i = 8 To 1 Step -1
If $iByteSize >= $iBytes_Val ^ $i Then Return Round($iByteSize / $iBytes_Val ^ $i, $iRound) & ' ' & $asBytes[$i]
Next
EndIf
EndFunc ;==>_String_GetFormatedSize
Func _GUICtrlCreateGroupEx($sText, $iLeft, $iTop, $iWidth, $iHeight, $iLineWidth = 3, $nColor = 0, $iStyle = 0, $sIcon = '', $nIconID = 0)
Local $aIDs[2] ;First + Last IDs
Local $nLabel_Style = $SS_ETCHEDFRAME
;1 to able set color for the Group frame
If $iStyle > 0 Then $nLabel_Style = $SS_SUNKEN
GUIStartGroup()
$aIDs[0] = GUICtrlCreateLabel('', $iLeft + 1, $iTop, $iWidth - 2, $iLineWidth, $nLabel_Style)
GUICtrlSetBkColor(-1, $nColor)
GUICtrlCreateLabel('', $iLeft + 2, $iTop + 5, $iLineWidth, $iHeight - 4, $nLabel_Style)
GUICtrlSetBkColor(-1, $nColor)
GUICtrlCreateLabel('', ($iLeft + $iWidth), $iTop - 3, $iLineWidth, $iHeight - 3, $nLabel_Style)
GUICtrlSetBkColor(-1, $nColor)
$aIDs[1] = GUICtrlCreateLabel('', $iLeft + 6, ($iTop + $iHeight) - 5, $iWidth, $iLineWidth, $nLabel_Style)
GUICtrlSetBkColor(-1, $nColor)
If $sText <> '' Then
If $sIcon <> '' Then
$iLeft += 15
$sText = ' ' & $sText
EndIf
$aIDs[1] = GUICtrlCreateLabel(' ' & $sText, $iLeft + 35, $iTop - 6)
GUICtrlSetColor(-1, $nColor)
EndIf
If $sIcon <> '' Then GUICtrlCreateIcon($sIcon, $nIconID, $iLeft + 25, $iTop - 8, 16, 16)
Return $aIDs
EndFunc ;==>_GUICtrlCreateGroupEx