Jump to content

Network adapters info


Recommended Posts

Hi!

How to add speed sensing of the adapter to this script:

MsgBox(64, "IP Addresses", _IPDetails())
Exit

Func _IPDetails()
    Local $sReturn = ""
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration", "WQL", 0x30), $aReturn[7] = [6]
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            If IsString($oObjectItem.IPAddress(0)) Then
                If IsString($oObjectItem.Description) Then
                    $aReturn[1] = "Description:" & @TAB & $oObjectItem.Description
                Else
                    $aReturn[1] = "Description:" & @TAB & "Not Available"
                EndIf

                If IsString($oObjectItem.MACAddress(0)) Then
                    $aReturn[2] = "MAC:" & @TAB & @TAB & $oObjectItem.MACAddress(0)
                Else
                    $aReturn[2] = "MAC:" & @TAB & @TAB & "Not Available"
                EndIf

                If IsBool($oObjectItem.DHCPEnabled) Then
                  $zGetIPType = $oObjectItem.DHCPEnabled
                  If $zGetIPType Then
                     $zGetIPType = "DHCP"
               Else
                     $zGetIPType = "Static"
                    EndIf
                    $aReturn[3] = $zGetIPType
                 EndIf

                If IsString($oObjectItem.IPAddress(0)) Then
                    $aReturn[4] = "IP Address:" & @TAB & $oObjectItem.IPAddress(0)
                Else
                    $aReturn[4] = "IP Address:" & @TAB & "Not Available"
                 EndIf

                 If IsString($oObjectItem.DefaultIPGateway(0)) Then
                    $aReturn[5] = "Default Gateway:" & @TAB & $oObjectItem.DefaultIPGateway(0)
                Else
                    $aReturn[5] = "Default Gateway:" & @TAB & "Not Available"
                EndIf

                If IsArray($oObjectItem.DNSServerSearchOrder()) Then
                    $aReturn[6] = "DNS Servers:" & @TAB & _WMIArrayToString($oObjectItem.DNSServerSearchOrder(), " - ")
                Else
                    $aReturn[6] = "DNS Servers:" & @TAB & "Not Available"
                EndIf


                $sReturn &= $aReturn[1] & @CRLF & $aReturn[2] & @CRLF & $aReturn[4] & @TAB & $aReturn[3] & @CRLF & $aReturn[5] & @CRLF & $aReturn[6] & @CRLF & @CRLF
            EndIf
        Next
        Return StringTrimRight($sReturn, 4)
    EndIf
    Return SetError(1, 0, $aReturn)
EndFunc   ;==>_IPDetails

Func _WMIArrayToString($aArray, $sDelimeter = "|")
    If IsArray($aArray) = 0 Then
        Return SetError(1, 0, "")
    EndIf
    Local $iUbound = UBound($aArray) - 1, $sString
    For $A = 0 To $iUbound
        $sString &= $aArray[$A] & $sDelimeter
    Next
    Return StringTrimRight($sString, StringLen($sDelimeter))
EndFunc   ;==>_WMIArrayToString

I assume what needs to be added "SELECT * FROM Win32_NetworkAdapter" and parameter "Speed".... But how?

Link to comment
Share on other sites

  • Moderators

@Scampy I would suggest you download AutoIt Script-o-Matic from the link below, and spend some time with it. The example script for Win32_NetworkAdapter will show you how to pull the information you're.

 

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

well, just create a second query for each record :

If IsObj($oColItems) Then
        For $oObjectItem In $oColItems

            $iIndex = $oObjectItem.InterfaceIndex
            $oAdapterInfos = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapter Where InterfaceIndex=" & $iIndex, "WQL", 0x30)
            If IsObj($oAdapterInfos) Then
                For $oAdapterInfo In $oAdapterInfos
                    $sSpeed = "Speed:" & @TAB & $oAdapterInfo.Speed & "kbps"
                Next
            Else
                $sSpeed =  "Speed:" & @TAB & "Not Available"
            EndIf
        Next
        .....

 

Link to comment
Share on other sites

On Windows 8 & 10 get-netadapter is the only one I found that could report back the duplex speed properly.

A bug on Intel i217 and i218 duplex detection algorithm would cause half duplex instead of full when you set it in the device properties as full duplex.

Any code/script would report back the "full duplex" setting that you have it set for, but only this PS cmdlet actually reported the real duplex back.

 

Just thought I would toss that out there.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...