Jump to content

Recommended Posts

Posted (edited)

Network Adapter Info use WMI (Windows Management Instrumentation)

 

Features: 

  • Show information network card.
  • Easily copy information, for copy just click on the line want to copy.
  • Notifications connection, connection loss.
  • Supports exporting information to file (CSV/INI format).

Run: 

Export to file INI format:   NetStatus.exe "PathFile.INI"   

Export to file CSV format:  NetStatus.exe "PathFile.CSV" CSV
Export to file CSV format:  NetStatus.exe "PathFile.CSV" /CSV
Export to file CSV format:  NetStatus.exe "PathFile.CSV" --CSV

 

 

UDF:

Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration

Global $oErrorHandler = ObjEvent("AutoIt.Error", "_SkipObjectError")
Func _SkipObjectError()
    ; Do nothing special, just check @error after suspect functions.
EndFunc   ;==>_SkipObjectError

Global $sAdapterInfo
Global Const $sNotAvailable = "N/A", $sBlankIP = "0.0.0.0", $sBlankMAC = "00:00:00:00:00:00"

ConsoleWrite(_PrintAdaptersInfo() & @CRLF)

;==>_GetDataSetVar
Func _PrintAdaptersInfo()
    If Not IsArray($sAdapterInfo) Then $sAdapterInfo = _GetListAdaptersInfo(".")
    Local $sIndex, $sAdapter, $sAdapterName, $sAdapterStatus, $sGetIPType, $sIP, $sSubNetIP, $sMAC, $sGetwayIP, $sGetwayMAC, $sSpeed, $sDNS1, $sDNS2, $sDNS3, $sDNS4, $sDNS5, $sDNS6, $sDNS7, $sDNS8, $sReturn
    If IsArray($sAdapterInfo) And $sAdapterInfo[0][0] > 0 Then
        For $x = 1 To $sAdapterInfo[0][0]
            $sIndex = $sAdapterInfo[$x][0]
            If ((_StringStripWSCR($sIndex) <> '') And ($sIndex <> $sNotAvailable)) Then $sReturn &= '+ Index: ' & $sIndex & @CRLF & ''
            $sAdapter = $sAdapterInfo[$x][1]
            If ((_StringStripWSCR($sAdapter) <> '') And ($sAdapter <> $sNotAvailable)) Then $sReturn &= '- Adapter: ' & $sAdapter & @CRLF & ''
            $sAdapterName = $sAdapterInfo[$x][2]
            If ((_StringStripWSCR($sAdapterName) <> '') And ($sAdapterName <> $sNotAvailable)) Then $sReturn &= '- Adapter Name: ' & $sAdapterName & @CRLF & ''
            $sAdapterStatus = $sAdapterInfo[$x][3]
            If ((_StringStripWSCR($sAdapterStatus) <> '') And ($sAdapterStatus <> $sNotAvailable)) Then $sReturn &= '- Adapter Status: ' & $sAdapterStatus & @CRLF & ''
            $sGetIPType = $sAdapterInfo[$x][4]
            If ((_StringStripWSCR($sGetIPType) <> '') And ($sGetIPType <> $sNotAvailable)) Then $sReturn &= '- IP Type: ' & $sGetIPType & @CRLF & ''
            $sIP = $sAdapterInfo[$x][5]
            If ((_StringStripWSCR($sIP) <> '') And ($sIP <> $sNotAvailable) And ($sIP <> $sBlankIP)) Then $sReturn &= '- IP: ' & $sIP & @CRLF & ''
            $sSubNetIP = $sAdapterInfo[$x][6]
            If ((_StringStripWSCR($sSubNetIP) <> '') And ($sSubNetIP <> $sNotAvailable) And ($sSubNetIP <> $sBlankIP)) Then $sReturn &= '- SubNet IP: ' & $sSubNetIP & @CRLF & ''
            $sMAC = $sAdapterInfo[$x][7]
            If ((_StringStripWSCR($sMAC) <> '') And ($sMAC <> $sNotAvailable) And ($sMAC <> $sBlankMAC)) Then $sReturn &= '- MAC: ' & $sMAC & @CRLF & ''
            $sGetwayIP = $sAdapterInfo[$x][8]
            If ((_StringStripWSCR($sGetwayIP) <> '') And ($sGetwayIP <> $sNotAvailable) And ($sGetwayIP <> $sBlankIP)) Then $sReturn &= '- Getway IP: ' & $sGetwayIP & @CRLF & ''
            $sGetwayMAC = $sAdapterInfo[$x][9]
            If ((_StringStripWSCR($sGetwayMAC) <> '') And ($sGetwayMAC <> $sNotAvailable) And ($sGetwayMAC <> $sBlankMAC)) Then $sReturn &= '- Getway MAC: ' & $sGetwayMAC & @CRLF & ''
            $sSpeed = $sAdapterInfo[$x][10]
            If ((_StringStripWSCR($sSpeed) <> '') And ($sSpeed <> $sNotAvailable)) Then $sReturn &= '- Speed: ' & $sSpeed & @CRLF & ''
            $sDNS1 = $sAdapterInfo[$x][11]
            If ((_StringStripWSCR($sDNS1) <> '') And ($sDNS1 <> $sNotAvailable) And ($sDNS1 <> $sBlankIP)) Then $sReturn &= '- DNS 1: ' & $sDNS1 & @CRLF & ''
            $sDNS2 = $sAdapterInfo[$x][12]
            If ((_StringStripWSCR($sDNS2) <> '') And ($sDNS2 <> $sNotAvailable) And ($sDNS2 <> $sBlankIP)) Then $sReturn &= '- DNS 2: ' & $sDNS2 & @CRLF & ''
            $sDNS3 = $sAdapterInfo[$x][13]
            If ((_StringStripWSCR($sDNS3) <> '') And ($sDNS3 <> $sNotAvailable) And ($sDNS3 <> $sBlankIP)) Then $sReturn &= '- DNS 3: ' & $sDNS3 & @CRLF & ''
            $sDNS4 = $sAdapterInfo[$x][14]
            If ((_StringStripWSCR($sDNS4) <> '') And ($sDNS4 <> $sNotAvailable) And ($sDNS4 <> $sBlankIP)) Then $sReturn &= '- DNS 4: ' & $sDNS4 & @CRLF & ''
            $sDNS5 = $sAdapterInfo[$x][15]
            If ((_StringStripWSCR($sDNS5) <> '') And ($sDNS5 <> $sNotAvailable) And ($sDNS5 <> $sBlankIP)) Then $sReturn &= '- DNS 5: ' & $sDNS5 & @CRLF & ''
            $sDNS6 = $sAdapterInfo[$x][16]
            If ((_StringStripWSCR($sDNS6) <> '') And ($sDNS6 <> $sNotAvailable) And ($sDNS6 <> $sBlankIP)) Then $sReturn &= '- DNS 6: ' & $sDNS6 & @CRLF & ''
            $sDNS7 = $sAdapterInfo[$x][17]
            If ((_StringStripWSCR($sDNS7) <> '') And ($sDNS7 <> $sNotAvailable) And ($sDNS7 <> $sBlankIP)) Then $sReturn &= '- DNS 7: ' & $sDNS7 & @CRLF & ''
            $sDNS8 = $sAdapterInfo[$x][18]
            If ((_StringStripWSCR($sDNS8) <> '') And ($sDNS8 <> $sNotAvailable) And ($sDNS8 <> $sBlankIP)) Then $sReturn &= '- DNS 8: ' & $sDNS8 & @CRLF & ''
            $sReturn &= @CRLF & ''
        Next
        Return $sReturn
    Else
        Return SetError(1, 0, '')
    EndIf
EndFunc   ;==>_PrintAdaptersInfo

Func _StringStripWSCR($iString = '')
    $iString = StringStripCR($iString)
    $iString = StringStripWS($iString, 8)
    Return $iString
EndFunc   ;==>_StringStripWSCR
;==>_GetListAdaptersInfo

Func _GetListAdaptersInfo($sComputer = ".")
    Local $Cols = 20, $strIndex, $objVAR, $objVARx, $zAdapter, $zAdapterName, $zSpeed, $zIndex, $zInterfaceIndex, $zGetIPType, $zAdapterStatus, $zIP, $zMAC, $zSubNetIP, $zGetwayIP, $zGetwayMAC
    Local $aReturn[1][$Cols] = [[0, $Cols]]
    If $sComputer = Default Then $sComputer = @ComputerName
    Local $sListIndexInterfaceName = _ListIndexInterfaceName()
    Local $objWMI = ObjGet("winmgmts:\\" & $sComputer & "\root\cimv2")
    Local $objWQLx = $objWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID != NULL", "WQL", 0x30)
;~  Local $objWQLx = $objWMI.ExecQuery('Select * From Win32_NetworkAdapter', "WQL", 0x30)
    If Not @error And IsObj($objWQLx) Then
        For $objVARx In $objWQLx
            $zAdapterName = $objVARx.NetConnectionID
            If (_StringStripWSCR($zAdapterName) = "") Then ContinueLoop
            $zSpeed = _ByteSuffixRound($objVARx.Speed) ; Vista+
            If Int($zSpeed) <= 0 Then
                For $z = 0 To UBound($sListIndexInterfaceName) - 1
                    If $sListIndexInterfaceName[$z][1] = $zAdapterName Then $zSpeed = _ByteSuffixRound(InterfaceIndexSpeed($sListIndexInterfaceName[$z][0]))
                Next
            EndIf
            $zAdapterStatus = $objVARx.NetConnectionStatus
            Switch $zAdapterStatus
                Case 0, 3
                    $zAdapterStatus = "Disable"
                Case 1, 2
                    $zAdapterStatus = "Connected"
                Case $zAdapterStatus = 7
                    $zAdapterStatus = "unPlugged"
                Case Else
                    $zAdapterStatus = $sNotAvailable
            EndSwitch
            $strIndex = $objVARx.Index
            Local $objWQL = $objWMI.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index=' & $strIndex, "WQL", 0x30)
            If Not @error And IsObj($objWQL) Then
                For $objVAR In $objWQL
                    $zAdapter = $objVAR.Description
                    $aReturn[0][0] += 1
                    $zIndex = $aReturn[0][0]
                    ReDim $aReturn[$zIndex * 2][$aReturn[0][1]]
                    $zInterfaceIndex = $objVAR.InterfaceIndex
                    If Int($zInterfaceIndex) <= 0 Then
                        For $z = 0 To UBound($sListIndexInterfaceName) - 1
                            If $sListIndexInterfaceName[$z][1] = $zAdapterName Then $zInterfaceIndex = $sListIndexInterfaceName[$z][0]
                        Next
                    EndIf
                    $aReturn[$zIndex][0] = $zInterfaceIndex
                    $aReturn[$zIndex][1] = $zAdapter
                    $aReturn[$zIndex][2] = $zAdapterName
                    $aReturn[$zIndex][3] = $zAdapterStatus
                    $zGetIPType = $objVAR.DHCPEnabled
                    If $zGetIPType Then
                        $zGetIPType = "DHCP"
                    Else
                        $zGetIPType = "StaticIP"
                    EndIf
                    $aReturn[$zIndex][4] = $zGetIPType
                    $zIP = $objVAR.IPAddress(0)
                    If _StringStripWSCR($zIP) = "" Then $zIP = $sNotAvailable
                    $aReturn[$zIndex][5] = $zIP
                    $zSubNetIP = $objVAR.IPSubnet(0)
                    If _StringStripWSCR($zSubNetIP) = "" Then $zSubNetIP = $sNotAvailable
                    $aReturn[$zIndex][6] = $zSubNetIP
                    $zMAC = $objVAR.MACAddress
                    If _StringStripWSCR($zMAC) = "" Then $zMAC = $sNotAvailable
                    $aReturn[$zIndex][7] = $zMAC
                    $zGetwayIP = $objVAR.DefaultIPGateway(0)
                    If _StringStripWSCR($zGetwayIP) = "" Then $zGetwayIP = $sNotAvailable
                    $aReturn[$zIndex][8] = $zGetwayIP
                    $zGetwayMAC = $sNotAvailable
                    If _StringStripWSCR($zGetwayIP) <> $sNotAvailable Then $zGetwayMAC = _GetMACFromIP($zGetwayIP)
                    $aReturn[$zIndex][9] = $zGetwayMAC
                    If Number($zSpeed) = 0 Then $zSpeed = $sNotAvailable
                    $aReturn[$zIndex][10] = $zSpeed
                    $aReturn[$zIndex][11] = $sNotAvailable
                    $aReturn[$zIndex][12] = $sNotAvailable
                    $aReturn[$zIndex][13] = $sNotAvailable
                    $aReturn[$zIndex][14] = $sNotAvailable
                    $aReturn[$zIndex][15] = $sNotAvailable
                    $aReturn[$zIndex][16] = $sNotAvailable
                    $aReturn[$zIndex][17] = $sNotAvailable
                    $aReturn[$zIndex][18] = $sNotAvailable
                    Local $zDNS = $objVAR.DNSServerSearchOrder()
                    Local $dnsCount = UBound($zDNS) - 1
                    $aReturn[$zIndex][19] = $dnsCount
                    If IsArray($zDNS) Then
                        Switch $dnsCount
                            Case 1
                                $aReturn[$zIndex][11] = $zDNS[0]
                            Case 2
                                $aReturn[$zIndex][11] = $zDNS[0]
                                $aReturn[$zIndex][12] = $zDNS[1]
                            Case 3
                                $aReturn[$zIndex][11] = $zDNS[0]
                                $aReturn[$zIndex][12] = $zDNS[1]
                                $aReturn[$zIndex][13] = $zDNS[2]
                            Case 4
                                $aReturn[$zIndex][11] = $zDNS[0]
                                $aReturn[$zIndex][12] = $zDNS[1]
                                $aReturn[$zIndex][13] = $zDNS[2]
                                $aReturn[$zIndex][14] = $zDNS[3]
                            Case 5
                                $aReturn[$zIndex][11] = $zDNS[0]
                                $aReturn[$zIndex][12] = $zDNS[1]
                                $aReturn[$zIndex][13] = $zDNS[2]
                                $aReturn[$zIndex][14] = $zDNS[3]
                                $aReturn[$zIndex][15] = $zDNS[4]
                            Case 6
                                $aReturn[$zIndex][11] = $zDNS[0]
                                $aReturn[$zIndex][12] = $zDNS[1]
                                $aReturn[$zIndex][13] = $zDNS[2]
                                $aReturn[$zIndex][14] = $zDNS[3]
                                $aReturn[$zIndex][15] = $zDNS[4]
                                $aReturn[$zIndex][16] = $zDNS[5]
                            Case 7
                                $aReturn[$zIndex][11] = $zDNS[0]
                                $aReturn[$zIndex][12] = $zDNS[1]
                                $aReturn[$zIndex][13] = $zDNS[2]
                                $aReturn[$zIndex][14] = $zDNS[3]
                                $aReturn[$zIndex][15] = $zDNS[4]
                                $aReturn[$zIndex][16] = $zDNS[5]
                                $aReturn[$zIndex][17] = $zDNS[6]
                            Case 8
                                $aReturn[$zIndex][11] = $zDNS[0]
                                $aReturn[$zIndex][12] = $zDNS[1]
                                $aReturn[$zIndex][13] = $zDNS[2]
                                $aReturn[$zIndex][14] = $zDNS[3]
                                $aReturn[$zIndex][15] = $zDNS[4]
                                $aReturn[$zIndex][16] = $zDNS[5]
                                $aReturn[$zIndex][17] = $zDNS[6]
                                $aReturn[$zIndex][18] = $zDNS[7]
                            Case Else
                                $aReturn[$zIndex][11] = $zDNS[0]
                        EndSwitch
                    EndIf
                Next
            EndIf
        Next
        Return $aReturn
    EndIf
    Return SetError(1, 0, "")
EndFunc   ;==>_GetListAdaptersInfo
Func _ListIndexInterfaceName()
    Local Const $tagIP_ADAPTER_ADDRESSES = "ulong Length;dword IfIndex;ptr Next;ptr AdapterName;ptr FirstUnicastAddress;" & "ptr FirstAnycastAddress;ptr FirstMulticastAddress;ptr FirstDnsServerAddress;ptr DnsSuffix;ptr Description;" & "ptr FriendlyName;byte PhysicalAddress[8];dword PhysicalAddressLength;dword Flags;dword Mtu;dword IfType;int OperStatus;" & "dword Ipv6IfIndex;dword ZoneIndices[16];ptr FirstPrefix;" & "uint64 TransmitLinkSpeed;uint64 ReceiveLinkSpeed;ptr FirstWinsServerAddress;ptr FirstGatewayAddress;" & "ulong Ipv4Metric;ulong Ipv6Metric;uint64 Luid;STRUCT;ptr Dhcpv4ServerSockAddr;int Dhcpv4ServerSockAddrLen;ENDSTRUCT;" & "ulong CompartmentId;STRUCT;ulong NetworkGuidData1;word NetworkGuidData2;word NetworkGuidData3;byte NetworkGuidData4[8];ENDSTRUCT;" & "int ConnectionType;int TunnelType;STRUCT;ptr Dhcpv6ServerSockAddr;int Dhcpv6ServerSockAddrLen;ENDSTRUCT;byte Dhcpv6ClientDuid[130];" & "ulong Dhcpv6ClientDuidLength;ulong Dhcpv6Iaid;ptr FirstDnsSuffix;"
    Local $aRet, $nBufSize, $stBuffer, $stIP_ADAPTER_ADDRESSES, $pIPAAStruct, $nIPAAStSize
    Local $pTemp, $nTemp, $nEntries, $aIndexEntries
    $aRet = DllCall("iphlpapi.dll", "ulong", "GetAdaptersAddresses", "ulong", 0, "ulong", 0x86, "ptr", 0, "ptr", 0, "ulong*", 0)
    If @error Then Return SetError(1, @error, "")
    If $aRet[0] Then
        If $aRet[0] <> 111 Or Not $aRet[5] Then Return SetError(2, $aRet[0], "")
    EndIf
    $nBufSize = $aRet[5]
    $stBuffer = DllStructCreate("int64;byte [" & $nBufSize & "];")
    $aRet = DllCall("iphlpapi.dll", "ulong", "GetAdaptersAddresses", "ulong", 0, "ulong", 0x86, "ptr", 0, "ptr", DllStructGetPtr($stBuffer), "ulong*", $nBufSize)
    If @error Then Return SetError(1, @error, "")
    If $aRet[0] Then Return SetError(2, $aRet[0], "")
    Dim $aIndexEntries[Floor($nBufSize / 72)][2]
    $nEntries = 0
    $pIPAAStruct = DllStructGetPtr($stBuffer)
    While $pIPAAStruct <> 0
        $stIP_ADAPTER_ADDRESSES = DllStructCreate($tagIP_ADAPTER_ADDRESSES, $pIPAAStruct)
        $nIPAAStSize = DllStructGetData($stIP_ADAPTER_ADDRESSES, "Length")
        $nTemp = DllStructGetData($stIP_ADAPTER_ADDRESSES, "OperStatus")
        If ($nTemp = 2 And Not False) Or DllStructGetData($stIP_ADAPTER_ADDRESSES, "IfType") = 24 Then
        Else
            $pTemp = DllStructGetData($stIP_ADAPTER_ADDRESSES, "FirstUnicastAddress")
            If $pTemp <> 0 Then
                $aIndexEntries[$nEntries][0] = DllStructGetData($stIP_ADAPTER_ADDRESSES, "IfIndex")
                $aIndexEntries[$nEntries][1] = _GetStringW_FromPtr(DllStructGetData($stIP_ADAPTER_ADDRESSES, "FriendlyName"))
                $nEntries += 1
            EndIf
        EndIf
        $pIPAAStruct = DllStructGetData($stIP_ADAPTER_ADDRESSES, "Next")
    WEnd
    If $nEntries = 0 Then Return SetError(-1, 0, "")
    ReDim $aIndexEntries[$nEntries][2]
    Return SetExtended($nEntries, $aIndexEntries)
EndFunc   ;==>_ListIndexInterfaceName

Func InterfaceIndexSpeed($IfIndex)
    Local $tBuffer, $pBuffer, $iResult, $iSpeed
    $tBuffer = DllStructCreate("wchar[256];dword[5];byte[8];dword[16];char[256]")
    $pBuffer = DllStructGetPtr($tBuffer)
    DllStructSetData($tBuffer, 2, $IfIndex, 1)
    $iResult = DllCall("iphlpapi.dll", "long", "GetIfEntry", "ptr", $pBuffer)
    If @error Then Return SetError(@error, @extended, 0)
    $iSpeed = DllStructGetData($tBuffer, 2, 4)
;~  $sDescr = DllStructGetData($tBuffer, 5)
    $tBuffer = 0
    Return SetError($iResult[0], $iSpeed / 1000 / 1000, $iSpeed)
EndFunc   ;==>InterfaceIndexSpeed
Func _GetStringW_FromPtr($pStr)
    If Not IsPtr($pStr) Or $pStr = 0 Then Return SetError(1, 0, "")
    Local $aRet = DllCall("kernel32.dll", "ptr", "lstrcpynW", "wstr", "", "ptr", $pStr, "int", 32767)
    If @error Or Not $aRet[0] Then Return SetError(@error, 0, "")
    Return $aRet[1]
EndFunc   ;==>_GetStringW_FromPtr

Func _GetMACFromIP($rMAC)
    If ($rMAC = "") Or ($rMAC = $sNotAvailable) Then Return $sNotAvailable
    Local $sbMAC = DllStructCreate("byte[6]")
    Local $siMAC = DllStructCreate("int")
    DllStructSetData($siMAC, 1, 6)
    Local $rHexMAC = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $rMAC)
    $rMAC = $rHexMAC[0]
    $rHexMAC = DllCall("iphlpapi.dll", "int", "SendARP", "int", $rMAC, "int", 0, "ptr", DllStructGetPtr($sbMAC), "ptr", DllStructGetPtr($siMAC))
    $rMAC = ""
    For $i = 0 To 5
        If $i Then $rMAC &= ":"
        $rMAC = $rMAC & Hex(DllStructGetData($sbMAC, 1, $i + 1), 2)
    Next
    If ($rMAC = "") Or ($rMAC = $sBlankMAC) Or ($rMAC = $sNotAvailable) Then Return $sNotAvailable
    Return $rMAC
EndFunc   ;==>_GetMACFromIP
;==>_ByteSuffixRound
Func _ByteSuffixRound($iBytes, $iRound = 2)
    $iBytes = Number($iBytes)
    If $iBytes > 1000000000 Then Return $sNotAvailable
    Local $A, $aArray[5] = ["Bps", "Kbps", "Mbps", "Gbps", "Tbps"]
    While $iBytes > 999
        $A += 1
        If $A > 3 Then ExitLoop
        $iBytes /= 1000
    WEnd
    Return Round($iBytes, $iRound) & " " & $aArray[$A]
EndFunc   ;==>_ByteSuffixRound
;==>CreateContentCSV
Func CreateContentCSV()
    Local $sContent
    If Not IsArray($sAdapterInfo) Then $sAdapterInfo = _GetListAdaptersInfo(".")
    If IsArray($sAdapterInfo) And $sAdapterInfo[0][0] > 0 Then
        $sContent &= '"NIC","InterfaceIndex","Adapter","AdapterName","AdapterStatus","GetIPType","IP","SubNetIP","MAC","GetwayIP","GetwayMAC","Speed","DNS1","DNS2","DNS3","DNS4","DNS5","DNS6","DNS7","DNS8"' & @CRLF
        For $x = 1 To $sAdapterInfo[0][0]
            $sContent &= '"' & $x & '",'
            $sContent &= '"' & $sAdapterInfo[$x][0] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][1] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][2] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][3] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][4] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][5] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][6] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][7] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][8] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][9] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][10] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][11] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][12] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][13] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][14] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][15] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][16] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][17] & '",'
            $sContent &= '"' & $sAdapterInfo[$x][18] & '"' & @CRLF
        Next
        Return $sContent
    Else
        Return SetError(1, 0, False)
    EndIf
EndFunc   ;==>CreateContentCSV
;==>CreateContentINI
Func CreateContentINI()
    Local $sContent = "[NetworkInfo]" & @CRLF
    $sContent &= "Time = " & @YEAR & "/" & @MON & "/" & @MDAY & "-" & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF
    If Not IsArray($sAdapterInfo) Then $sAdapterInfo = _GetListAdaptersInfo(".")
    If IsArray($sAdapterInfo) And $sAdapterInfo[0][0] > 0 Then
        $sContent &= "TotalNIC = " & $sAdapterInfo[0][0] & @CRLF & @CRLF
        For $x = 1 To $sAdapterInfo[0][0]
            $sContent &= "[NIC" & $x & "]" & @CRLF
            $sContent &= "InterfaceIndex = " & $sAdapterInfo[$x][0] & @CRLF
            $sContent &= "Adapter = " & $sAdapterInfo[$x][1] & @CRLF
            $sContent &= "AdapterName = " & $sAdapterInfo[$x][2] & @CRLF
            $sContent &= "AdapterStatus = " & $sAdapterInfo[$x][3] & @CRLF
            $sContent &= "GetIPType = " & $sAdapterInfo[$x][4] & @CRLF
            $sContent &= "IP = " & $sAdapterInfo[$x][5] & @CRLF
            $sContent &= "SubNetIP = " & $sAdapterInfo[$x][6] & @CRLF
            $sContent &= "MAC = " & $sAdapterInfo[$x][7] & @CRLF
            $sContent &= "GetwayIP = " & $sAdapterInfo[$x][8] & @CRLF
            $sContent &= "GetwayMAC = " & $sAdapterInfo[$x][9] & @CRLF
            $sContent &= "Speed = " & $sAdapterInfo[$x][10] & @CRLF & @CRLF
            $sContent &= "DNS1 = " & $sAdapterInfo[$x][11] & @CRLF
            $sContent &= "DNS2 = " & $sAdapterInfo[$x][12] & @CRLF
            $sContent &= "DNS3 = " & $sAdapterInfo[$x][13] & @CRLF
            $sContent &= "DNS4 = " & $sAdapterInfo[$x][14] & @CRLF
            $sContent &= "DNS5 = " & $sAdapterInfo[$x][15] & @CRLF
            $sContent &= "DNS6 = " & $sAdapterInfo[$x][16] & @CRLF
            $sContent &= "DNS7 = " & $sAdapterInfo[$x][17] & @CRLF
            $sContent &= "DNS8 = " & $sAdapterInfo[$x][18] & @CRLF
        Next
        Return $sContent
    Else
        Return SetError(1, 0, False)
    EndIf
EndFunc   ;==>CreateContentINI
;==>_CheckConnect

 


Binary and Source: 

 

Edited by Trong
fix bugs and add features

Regards,
 

Posted

Thanks for this worthwhile utility script.  I was able to get the result I expected on the first PC I tested (shown below).

However, on a second PC that had its network adapter disabled by the control panel settings, the script got an "incorrect number of subscripts" error.  I inserted an _ArrayDisplay() statement.  The array shows only one row with 0 and 5 in the columns. 

Can your utility be made to show all adapters in the PC, even those that are disabled?

Thanks for any help you can give.

5716f50a50190_ArrayContents.PNG.0646a628

Posted (edited)
On 20/4/2016 at 10:21 AM, qwert said:

Thanks for this worthwhile utility script.  I was able to get the result I expected on the first PC I tested (shown below).

However, on a second PC that had its network adapter disabled by the control panel settings, the script got an "incorrect number of subscripts" error.  I inserted an _ArrayDisplay() statement.  The array shows only one row with 0 and 5 in the columns. 

Can your utility be made to show all adapters in the PC, even those that are disabled?

Thanks for any help you can give.

5716f50a50190_ArrayContents.PNG.0646a628

Show all adapters in the PC (no incude special Adapters) , 
but if Adapter disabled then only get a name 
can't get more info !

Edited by VIP

Regards,
 

Posted

try this:

#include <array.au3>

$iPid = run("powershell get-netadapter -IncludeHidden -verbose" , "" , @SW_HIDE , $stdout_child)

$sOutput = ""

     While 1
        $sOutput &= StdoutRead($iPID)
        If @error Then ExitLoop
    WEnd


ProcessClose($iPID)

$aOut = stringsplit($sOutput , @LF , 2)

_ArrayDisplay($aOut)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted
10 minutes ago, iamtheky said:

try this:

#include <array.au3>

$iPid = run("powershell get-netadapter -IncludeHidden -verbose" , "" , @SW_HIDE , $stdout_child)

$sOutput = ""

     While 1
        $sOutput &= StdoutRead($iPID)
        If @error Then ExitLoop
    WEnd


ProcessClose($iPID)

$aOut = stringsplit($sOutput , @LF , 2)

_ArrayDisplay($aOut)

 

Only get MacAddress, not have IP info. And can't run if not install/have PowerShell

Regards,
 

Posted
20 minutes ago, VIP said:

And can't run if not install/have PowerShell

What Version of Windows are you using that doesn't come with PS by default?

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 Gude
How 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

Posted (edited)
On 20/4/2016 at 11:49 PM, BrewManNH said:

What Version of Windows are you using that doesn't come with PS by default?

Windows XP and Windows 7/8/8.1/10 (Lite version - very popular) not have PS by default

And Get-NetAdapter Applies To: Windows 8.1, Windows PowerShell 4.0, Windows Server 2012 R2 and higher

Edited by VIP

Regards,
 

Posted

I just moved to win10. lots of good fun in powershell 5.0

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted

so how can I get Network Adapters information via PS? 
"powershell get-netadapter" command on only  get the Name and MAC address, without IP information.

Regards,
 

Posted (edited)

get-netipaddress

Though, that will be the return of adapters that are not disabled.

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted

Thanks for the update.  I now have 11 devices identified on one of my PCs.  Here's a sampling:

WAN Miniport (SSTP)
WAN Miniport (IKEv2)
:
Bluetooth Device (Personal Area Network)
:
Intel(R) 82578DC Gigabit Network Connection

But only two of them have any information listed for them.  Should it be finding 11 Network Adapters?  Can it be made to find only the 2 or 3 actual hardware devices?

Posted

Update new version! 
Code optimized and fast and faster.
enjoy!

P/S: I do not know how to delete old screenshot!

Regards,
 

Posted

@VIP: Thanks for this latest update.  I've tested it on two PCs running Win7 Pro and it fetches the information accurately.

Very good work!

  • Trong changed the title to Get Network Adapter Info

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
×
×
  • Create New...