Jump to content

[Solved] Detect LAN speed


Recommended Posts

Hi, I am trying to make script that detects the actual speed of my Wlan - it sometimes stucks on 5.5 Mbits and i have to reconnect to wlan to get the full speed again.

I've been searching quite long for func that can retrieve the information - without success.

Now I found some function on MSDN that should be able to return the speed - MultinetGetConnectionPerformance.

The point is that the function requires input from another function and that from another function, ... and so I got lost. I really dont know how to continue so I would be glad if somebody gives me a helping hand.

;http://msdn.microsoft.com/en-us/library/aa385353(VS.85).aspx
;typedef struct _NETRESOURCE {DWORD  dwScope;DWORD  dwType;DWORD  dwDisplayType;DWORD  dwUsage;LPTSTR lpLocalName;LPTSTR lpRemoteName;LPTSTR lpComment;  LPTSTR lpProvider;
Local $NETRESOURCESTRUCT    = DllStructCreate('dword;dword;dword;dword;str;str;str;str')

;typedef struct _NETCONNECTINFOSTRUCT { DWORD cbStructure;  DWORD dwFlags;  DWORD dwSpeed;  DWORD dwDelay;  DWORD dwOptDataSize;
Local $NETCONNECTINFOSTRUCT = DllStructCreate('dword cbStructure;dword dwFlags;dword dwSpeed;dword dwDelay;dword deOptDataSize')

#cs
http://msdn.microsoft.com/en-us/library/aa385449(VS.85).aspx
  __in   HANDLE hEnum,
  __inout  LPDWORD lpcCount,
  __out LPVOID lpBuffer,
  __inout  LPDWORD lpBufferSize
);
#ce
DllCall('Mpr.dll', 'dword', 'WNetEnumResource', 'ptr', $hEnum, 'dword*', $lpcCount, 'ptr', $lpBuffer, 'dword*', $lpBufferSize)

; http://msdn.microsoft.com/en-us/library/aa385342(VS.85).aspx
DllCall('Mpr.dll', 'dword', 'MultinetGetConnectionPerformance', 'ptr', DllStructGetPtr($NETRESOURCESTRUCT), 'ptr', DllStructGetPtr($NETCONNECTINFOSTRUCT))

MsgBox(0, '', DllStructGetData($NETCONNECTINFOSTRUCT, 'dwSpeed'))
Edited by Markos
Link to comment
Share on other sites

Try out my Performance Counters UDF, see if there's something there you can use - its in my signature.

I recommend trying the 'TestPDH_PerformanceCounters' function and going to 'Manual Entry' (after the initial selection box - which you can't bypass currently, so select anything and go to the next screen) and enter this:

\Network Interface(*)\*

If you have multiple cards, it will list them all, but you can adjust it for the card you want to look at (the wildcard in parentheses should be modified).

Hope maybe that helps *shrug*

Edited by ascendant
Link to comment
Share on other sites

Why not time how long it takes to download a small-ish file by FTP or HTTP? MultinetGetConnectionPerformance is only making a guess based on recent throughput so this method would probably be just as reliable ...

WBD

Link to comment
Share on other sites

So I have finally took deeper look into ascendant's functions.

Thank you - your funcs are gr8 piece of work, that is exactly what I was looking for.

If anybody is interested in what I was trying to accomplish - here is the code:

#include "_PDH_PerformanceCounters.au3"
#include "Native_Wifi_Func_V2_1.au3"

Local  $sObject = '\Rozhraní sítě(Bezdrátová dvoupásmová minikarta Dell 1490 WLAN)\Aktuální šířka pásma'
Global $sSSID   = 'Mi-Fi'
Global $iRecheckTime = 60000
Global $iReconnectIfLowerThan = 5500000

Global $hPDH_QueryHandle    = _PDH_GetNewQueryHandle()
Global $hPDH_CounterHandle  = _PDH_AddCounter($hPDH_QueryHandle, $sObject)
Global $hClientHandle       = _Wlan_OpenHandle()
Global $pGUID               = _Wlan_EnumInterfaces($hClientHandle)

Global $aInterfaceRes
While 1
    $aInterfaceRes = _Wlan_QueryInterface($hClientHandle, $pGUID[0][0], 3)
;~  If Not IsArray($aInterfaceRes) ThenConsoleWrite('Disconnected' & @CRLF)

    If IsArray($aInterfaceRes) And $aInterfaceRes[1] = $sSSID And _PDH_UpdateCounter($hPDH_QueryHandle,$hPDH_CounterHandle) <= $iReconnectIfLowerThan Then
        _Wlan_Disconnect($hClientHandle, $pGUID[0][0])
        _Wlan_Connect($hClientHandle, $pGUID[0][0], $sSSID)
    EndIf

    Sleep($iRecheckTime)
WEnd

Func OnAutoItExit()
    _Wlan_CloseHandle($hClientHandle)
    _PDH_FreeQueryHandle($hPDH_QueryHandle)
    _PDH_UnInit($hPDH_QueryHandle)
EndFunc
Link to comment
Share on other sites

Glad I could help, not quite sure what Counter you are using (don't understand that language) - but you forgot an important part of the code - _PDH_Init(). That should be called prior to getting new Query Handles. It will prevent the Query Handles & Counter Handles from returning constant errors.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...