mdwerne Posted June 28, 2013 Share Posted June 28, 2013 So the code below is mostly from a post by UEZ, but I've modified it a bit for my application. What I'm trying to do is read all MAC address's (either connected or not) into an array and then pull the Mac address out of the DHCPv6DUID to see if there is a match. For the code below to work, you need IPv6 enabled and for my application, (HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservicesTCPIP6Parameters,DisabledComponents) set to 1. In the end I will compare the two values (Mac from the DHCPv6DUID and any of the MACs in the array) if they match, do nothing, if not...do something else. Hope this makes sense, bottomline is how do I match a string value against a column in an array. Here is my code to grab the string and the array. expandcollapse popup#include <Array.au3> $sHost = @ComputerName $Dhcpv6DUID = RegRead("HKLM\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters", "Dhcpv6DUID") $aNetworkAdapters = WMI_ListAllNetworkAdapters($sHost) Dim $DUIDMAC = "", $xt = 1 $String = StringTrimLeft($Dhcpv6DUID, 18) $Result = StringSplit($String, "") For $x = 1 To $Result[0] If $x = $xt + 2 Then $xt = $x $DUIDMAC = $DUIDMAC & ":" EndIf $DUIDMAC = $DUIDMAC & $Result[$x] Next MsgBox(0,"MAC From DHCPv6DUID",$DUIDMAC) _ArrayDisplay($aNetworkAdapters) Func WMI_ListAllNetworkAdapters($sHost) Local $objWMIService = ObjGet("winmgmts:\\" & $sHost & "\root\cimv2") If @error Then Return SetError(1, 0, 0) Local $aStatus[13] = ["Disconnected", "Connecting", "Connected", "Disconnecting", "Hardware not present", "Hardware disabled", "Hardware malfunction", _ "Media Disconnected", "Authenticating", "Authentication Succeeded", "Authentication Failed", "Invalid Address", "Credentials Required"] ; $colItems = $objWMIService.ExecQuery("SELECT MACAddress, Name, NetConnectionID, NetConnectionStatus FROM Win32_NetworkAdapter", "WQL", 0x30) $colItems = $objWMIService.ExecQuery("SELECT MACAddress, NetConnectionStatus FROM Win32_NetworkAdapter", "WQL", 0x30) Local $aNetworkAdapters[1000][2], $i = 0, $iPointer If IsObj($colItems) Then For $objItem in $colItems With $objItem ;$aNetworkAdapters[$i][0] = .NetConnectionID ;$aNetworkAdapters[$i][1] = .Name $aNetworkAdapters[$i][0] = .MACAddress $aNetworkAdapters[$i][1] = $aStatus[.NetConnectionStatus * 1] EndWith $i += 1 Next ReDim $aNetworkAdapters[$i][2] Return $aNetworkAdapters Else Return SetError(2, 0, 0) EndIf EndFunc Thanks for any suggestions, -Mike Link to comment Share on other sites More sharing options...
BrewManNH Posted June 28, 2013 Share Posted June 28, 2013 Try this and see if it gives you what you're looking for. expandcollapse popup#include <Array.au3> #include <Constants.au3> $sHost = @ComputerName $Dhcpv6DUID = RegRead("HKLM\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters", "Dhcpv6DUID") $aNetworkAdapters = WMI_ListAllNetworkAdapters($sHost) Global $DUIDMAC = "", $xt = 1 $String = StringTrimLeft($Dhcpv6DUID, 18) $Result = StringSplit($String, "") For $x = 1 To $Result[0] If $x = $xt + 2 Then $xt = $x $DUIDMAC = $DUIDMAC & ":" EndIf $DUIDMAC = $DUIDMAC & $Result[$x] Next For $Count = 1 to Ubound($aNetworkAdapters) - 1 If $aNetworkAdapters[$Count][0] = $DUIDMAC Then MsgBox($mb_systemmodal, "Found it", "Found the MAC address in the array at: " & $Count) ExitLoop EndIf Next MsgBox(0, "MAC From DHCPv6DUID", $DUIDMAC) _ArrayDisplay($aNetworkAdapters) Func WMI_ListAllNetworkAdapters($sHost) Local $objWMIService = ObjGet("winmgmts:\\" & $sHost & "\root\cimv2") If @error Then Return SetError(1, 0, 0) Local $aStatus[13] = ["Disconnected", "Connecting", "Connected", "Disconnecting", "Hardware not present", "Hardware disabled", "Hardware malfunction", _ "Media Disconnected", "Authenticating", "Authentication Succeeded", "Authentication Failed", "Invalid Address", "Credentials Required"] ; $colItems = $objWMIService.ExecQuery("SELECT MACAddress, Name, NetConnectionID, NetConnectionStatus FROM Win32_NetworkAdapter", "WQL", 0x30) $colItems = $objWMIService.ExecQuery("SELECT MACAddress, NetConnectionStatus FROM Win32_NetworkAdapter", "WQL", 0x30) Local $aNetworkAdapters[1000][2], $i = 0, $iPointer If IsObj($colItems) Then For $objItem In $colItems With $objItem ;$aNetworkAdapters[$i][0] = .NetConnectionID ;$aNetworkAdapters[$i][1] = .Name $aNetworkAdapters[$i][0] = .MACAddress $aNetworkAdapters[$i][1] = $aStatus[.NetConnectionStatus * 1] EndWith $i += 1 Next ReDim $aNetworkAdapters[$i][2] Return $aNetworkAdapters Else Return SetError(2, 0, 0) EndIf EndFunc ;==>WMI_ListAllNetworkAdapters If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
mdwerne Posted June 28, 2013 Author Share Posted June 28, 2013 @BrewManNH - Why yes indeedy, that gets me EXACTLY what I needed! Thank you very much. -Mike 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