Page 1 sur 1
[R] Détection type connexion réseau
Posté : jeu. 24 oct. 2013 22:31
par jcaspar
B
onjour à tous !
Je souhaiterais pouvoir détecter le type de connexion réseau utilisée ( réseau local ou Wifi )
pensez vous que cela soit possible ? ( Sur un pc portable il est possible soit d'utiliser
le réseau local, soit du wifi suivant le cas de figure je souhaiterais pouvoir configurer le proxy
d'internet explorer )
Merci pour vos idées et conseil !
Jean-Marc
Re: [..] Détection type connexion réseau
Posté : ven. 25 oct. 2013 00:00
par jguinch
Salut
Pour savoir si c'est du Wifi ou non :
(la fonction n'est pas de moi, je ne sais plus ou j'ai récupéré ça...)
► Afficher le texte
Code : Tout sélectionner
; #FUNCTION# ====================================================================================================================
; Name...........: _IsWirelessAdapter
; Description....: Checks if a network adapter is a wireless type
; Syntax.........: _IsWirelessAdapter($sAdapter)
; Parameters.....: $sNetAdapter - Name of the network adapter
; Return values..: Success - Returns 1
; Failure - 0
; ===============================================================================================================================
Func _IsWirelessAdapter($sAdapter)
Local $hDLL = DllOpen("wlanapi.dll"), $aResult, $hClientHandle, $pInterfaceList, _
$tInterfaceList, $iInterfaceCount, $tInterface, $pInterface, $tGUID, $pGUID
$aResult = DllCall($hDLL, "dword", "WlanOpenHandle", "dword", 2, "ptr", 0, "dword*", 0, "hwnd*", 0)
If @error Or $aResult[0] Then Return 0
$hClientHandle = $aResult[4]
$aResult = DllCall($hDLL, "dword", "WlanEnumInterfaces", "hwnd", $hClientHandle, "ptr", 0, "ptr*", 0)
If @error Or $aResult[0] Then Return 0
$pInterfaceList = $aResult[3]
$tInterfaceList = DllStructCreate("dword", $pInterfaceList)
$iInterfaceCount = DllStructGetData($tInterfaceList, 1)
If Not $iInterfaceCount Then Return 0
Local $abGUIDs[$iInterfaceCount]
For $i = 0 To $iInterfaceCount - 1
$pInterface = Ptr(Number($pInterfaceList) + ($i * 532 + 8))
$tInterface = DllStructCreate("byte GUID[16]; wchar descr[256]; int State", $pInterface)
$abGUIDs[$i] = DllStructGetData($tInterface, "GUID")
If DllStructGetData($tInterface, "descr") == $sAdapter Then Return 1
Next
DllCall($hDLL, "dword", "WlanFreeMemory", "ptr", $pInterfaceList)
$tGUID = DllStructCreate("byte[16]")
DllStructSetData($tGUID, 1, $abGUIDs[0])
$pGUID = DllStructGetPtr($tGUID)
DllCall($hDLL, "dword", "WlanCloseHandle", "ptr", $hClientHandle, "ptr", 0)
DllClose($hDLL)
Return 0
EndFunc ; ===> _IsWirelessAdapter
Re: [..] Détection type connexion réseau
Posté : ven. 25 oct. 2013 00:05
par Tlem
La fonction de jguinch test un adaptateur mais n'indique pas quelle interface est utilisée (La fonction ci-dessous non plus d'ailleurs ^^). Par contre elle permet de savoir si l'interface Wlan est connecté ou non.
Ca devrait être suffisant dans votre cas pour tester si on utilise le Wlan ou le Lan. Par contre si les deux sont branchés ...
Tiré de
ce sujet :
► Afficher le texte
Code : Tout sélectionner
Opt('MustDeclareVars', 1)
If Check_WLAN_Status() Then
MsgBox(64, "Info", "Wlan connecté")
Else
MsgBox(32, "Info", "Wlan déconecté")
EndIf
Func Check_WLAN_Status()
Local $instance_name, $WLAN_adapter_A[1], $i = 0
Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\wmi")
Local $colItems = $objWMIService.ExecQuery("SELECT * FROM MSNdis_80211_Configuration")
For $objItem In $colItems
$WLAN_adapter_A[$i] = $objItem.InstanceName ; get name of WLAN-apdater
$i += 1
ReDim $WLAN_adapter_A[$i + 1]
Next
Local $objWin = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Local $NetCards = $objWin.ExecQuery("Select * From Win32_NetworkAdapter where NetConnectionStatus=2")
For $i = 0 To UBound($WLAN_adapter_A) - 1
For $objNetCard In $NetCards
If StringInStr($WLAN_adapter_A[$i], $objNetCard.Name) <> 0 Then Return 1
Next
Next
Return 0
EndFunc ;==>Check_WLAN_Status
Re: [..] Détection type connexion réseau
Posté : ven. 25 oct. 2013 11:43
par jguinch
En fait, j'avais fait un UDF, qui va permettre de faire ça facilement
http://www.autoitscript.fr/forum/viewto ... 21&t=11207
Code : Tout sélectionner
#Include "Network.au3"
$aNetList = _GetNetworkAdapterInfos()
For $i = 0 To UBound($aNetList, 1) - 1
If $aNetList[$i][9] = 2 AND _IsWirelessAdapter($aNetList[$i][7]) Then
MsgBox(0, "", "La connexion Wifi est active")
ExitLoop
EndIf
Next
Re: [..] Détection type connexion réseau
Posté : mer. 19 févr. 2014 21:09
par jcaspar
Merci beaucoup pour vos réponses cela répond pleinement à ma question !