Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Compare an array column to a string?

$
0
0

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_MACHINE\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters,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.

AutoIt         
#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


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>