scubar 1 Posted June 21, 2013 Share Posted June 21, 2013 (edited) Hi Guys Am hoping someone here will probably solve this problem I can't seem to get my head around. I basically want to get the NetconnectionID, MACAddress IPAddress(0) and IPAddress(1) all into the same array making sure that the IP addresses match the MACaddress. Heres the code ive managed to come up with which creates two seperate arrays but I just dont know how to combine them into a single array. expandcollapse popupFunc _GetNetworkInfo() Local $sArray1 [1] [4] Local $sArray2 [1] [4] $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $sWMIService = "winmgmts:\\.\root\CIMV2" $objWMIService = ObjGet($sWMIService) If IsObj($objWMIService) Then $colItems1 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter " _ & "where NetConnectionStatus=2", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems1) Then For $objItem1 in $colItems1 ReDim $sArray1 [UBound($sArray1) + 1] [4] $sArray1 [UBound($sArray1) - 1] [0] = $objItem1.NetConnectionID $sArray1 [UBound($sArray1) - 1] [1] = $objItem1.MACAddress Next Else MsgBox(16, "Error", "Failed to get Win32_NetworkAdapter") EndIf _ArrayDisplay($sArray1) $colItems2 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration " _ & "where IPEnabled=TRUE", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems2) Then For $objItem2 in $colItems2 ReDim $sArray2 [UBound($sArray2) + 1] [4] $sArray2 [UBound($sArray2) - 1] [1] = $objItem2.MACAddress $sArray2 [UBound($sArray2) - 1] [2] = $objItem2.IPAddress(0) $sArray2 [UBound($sArray2) - 1] [3] = $objItem2.IPAddress(1) Next Else MsgBox(16, "Error", "Failed to get Win32_NetworkAdapterConfiguration") EndIf _ArrayDisplay($sArray2) Else MsgBox(4096, "Error", "Failed to connect to WMI at: " & $sWMIService) EndIf Return EndFunc I did try and create a script that did the same as this vbs code I found but I couldnt seem to get it working. For Each objNetAdapter in colNetAdapters strMACAddress = objNetAdapter.MACAddress Next Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_NetworkAdapterConfiguration") For Each objItem in colItems If objItem.MACAddress = strMACAddress Then strIPAddress = objNetAdapter.IPAddress Any help would be greatly appreciated. Edited June 21, 2013 by scubar Link to post Share on other sites
UEZ 1,435 Posted June 21, 2013 Share Posted June 21, 2013 expandcollapse popup#include <Array.au3> _GetNetworkInfo() Func _GetNetworkInfo() Local $sArray1[1][4] Local $sArray2[1][4] $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $sWMIService = "winmgmts:\\.\root\CIMV2" $objWMIService = ObjGet($sWMIService) If IsObj($objWMIService) Then $colItems1 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter " _ & "where NetConnectionStatus=2", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems1) Then For $objItem1 In $colItems1 ReDim $sArray1[UBound($sArray1) + 1][4] $sArray1[UBound($sArray1) - 1][0] = $objItem1.NetConnectionID $sArray1[UBound($sArray1) - 1][1] = $objItem1.MACAddress Next Else MsgBox(16, "Error", "Failed to get Win32_NetworkAdapter") EndIf ;~ _ArrayDisplay($sArray1) $colItems2 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration " _ & "where IPEnabled=TRUE", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems2) Then Local $y = 1 For $objItem2 In $colItems2 $sArray1[$y][2] = $objItem2.MACAddress $sArray1[$y][3] = $objItem2.IPAddress(0) $y += 1 Next Else MsgBox(16, "Error", "Failed to get Win32_NetworkAdapterConfiguration") EndIf _ArrayDisplay($sArray1) Else MsgBox(4096, "Error", "Failed to connect to WMI at: " & $sWMIService) EndIf Return EndFunc ;==>_GetNetworkInfo Br, UEZ Try this: Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to post Share on other sites
Solution scubar 1 Posted June 21, 2013 Author Solution Share Posted June 21, 2013 (edited) Thanks Luckily I had a moment of clarity and managed to work out how to do it by checking MAC address using the _ArraySearch function and using the index found. Below is the complete code for the function expandcollapse popup Func _GetNetworkInfo() Local $sArray [1] [4] $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $sWMIService = "winmgmts:\\.\root\CIMV2" $objWMIService = ObjGet($sWMIService) If IsObj($objWMIService) Then $colItems1 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter " _ & "where NetConnectionStatus=2", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems1) Then For $objItem1 in $colItems1 ReDim $sArray [UBound($sArray) + 1] [4] $sArray [UBound($sArray) - 1] [0] = $objItem1.NetConnectionID $sArray [UBound($sArray) - 1] [1] = $objItem1.MACAddress Next Else MsgBox(16, "Error", "Failed to get Win32_NetworkAdapter") EndIf $colItems2 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration " _ & "where IPEnabled=TRUE", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems2) Then For $objItem2 in $colItems2 $i = _ArraySearch($sArray,$objItem2.MACAddress, 0) $sArray [$i] [2] = $objItem2.IPAddress(0) $sArray [$i] [3] = $objItem2.IPAddress(1) Next Else MsgBox(16, "Error", "Failed to get Win32_NetworkAdapterConfiguration") EndIf Else MsgBox(4096, "Error", "Failed to connect to WMI at: " & $sWMIService) EndIf Return $sArray EndFunc No doubt I'll probably be back posting again shortly. Now that I have the Array I need to use it in a GUI I'm creating that will display the information based on the Network Connection ID Edited June 21, 2013 by scubar Link to post Share on other sites
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