Page 1 of 1 1
Topic Options
#135857 - 2005-03-17 04:29 AM Check NicSpeed Script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Looked for a script to check the NIC Speed setting but could not find one so I wrote this one.

I attempted to use WMI but the returned data was blank for my test systems.
AutoSense: was blank
Speed: was blank

This script attempts to determine what the current Network card Speed settings are set to.
This appears to work for all those involved in coding/testing but may not work for all systems. If you do test the code and find that it does not function correctly please post with some details so that we can attempt to make the code better.

NOTE: Code was updated to now support more NIC cards and operate against remote computers if you fill in the $sComputer value with the name of a remote computer.


Original Code
NTDOC

Contributors Thanks for the help in completing this script
Glenn Barnas - Debugging, Code ideas
Bryce - Code ideas
Shawn - Code ideas, Testing
Les - Testing
Al - Testing


Examples of output are:
  • Device Name: Broadcom 570x Gigabit Integrated Controller
    Device Index: 0001
    Speed Setting: Auto
    Media Type: 0
  • Device Name: Broadcom NetXtreme Gigabit Ethernet for hp
    Device Index: 0007
    Speed Setting: Auto
    Media Type: 0
  • Device Name: HP NC7770 Gigabit Server Adapter
    Device Index: 0000
    Speed Setting: 100 Mb Full
    Media Type: 4102
    Device Name: HP NC7770 Gigabit Server Adapter
    Device Index: 0006
    Speed Setting: 100 Mb Full
    Media Type: 4102
  • Device Name: HP NC7781 Gigabit Server Adapter
    Device Index: 0002
    Speed Setting: Undetermined probably 1000 Full
    Media Type: 8
    Device Name: HP NC7781 Gigabit Server Adapter
    Device Index: 0003
    Speed Setting: Undetermined probably 1000 Full
    Media Type: 8
  • Device Name: Intel(R) PRO/100 VM Network Connection
    Device Index: 0002
    Speed Setting: Auto Detect
    Media Type: 0
  • Device Name: Intel(R) PRO/100+ Management Adapter
    Device Index: 0007
    Speed Setting: Auto Detect
    Media Type: 0
  • Device Name: Linksys LNE100TX Fast Ethernet Adapter(LNE100TX v4)
    Device Index: 0001
    Speed Setting: AutoSense
    Media Type: 0
  • Device Name: 3Com Gigabit LOM (3C940)
    Device Index: 0010
    Speed Setting: Auto
    Media Type: Autoselect
  • Device Name: AMD PCNET Family PCI Ethernet Adapter
    Device Index: 0001
    Speed Setting: Auto Detect
    Media Type: 0
  • Device Name: HP NC7770 Gigabit Server Adapter
    Device Index: 0000
    Speed Setting: 1000 Mb Full
    Media Type: 8200


Break On

Dim $SO,$Pause
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('WrapAtEOL','On')


; Main code (function) starts here...
DIM $Index, $BadAdapters, $Type, $Types, $Speed, $Name, $sComputer
DIM $HKLMSCCSCC, $NicData, $Key, $DeviceID, $MediaType, $RequestedMediaType


; Enter the name of the remote computer here, if left blank will check current Computer
$sComputer=''


; Add UNC to Computer name if $sComputer name supplied
If $sComputer $sComputer = '\\' + $sComputer + '\' EndIf
If InStr($sComputer,@WKSTA) $sComputer="" EndIf


; List of adapter names that are not NICs. Any name that ends with a (val)
; will be trimmed to eliminate the parens and the data in them.
$BadAdapters = '~Miniport Wan~RAS Async~Direct Parallel~'


; Main registry key to enumerate
$HKLMSCCSCC=$sComputer+'HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}'


; Get a list of NICs from the registry
$NicData = ArrayEnumKey($HKLMSCCSCC)


; Examine each entry
For Each $Key In $NicData


; Read the Driver Description
$DeviceID = ReadValue($HKLMSCCSCC+'\'+$Key,'DriverDesc')


; If not null, and not in the list of Bad Adapters, try to identify the speed parameter
If $DeviceID And Not InSTR($BadAdapters, '~' + Trim(Split($DeviceID, '(')[0]) + '~')


Select
; Intel adapters
Case InStr($DeviceID,'Intel')
$Name='SpeedDuplex'


; Broadcom and HP adapters
Case InStr($DeviceID,'Broadcom') Or InStr($DeviceID,'HP NC7781')
Or InStr($DeviceID,'HP NC7770')
$Name='RequestedMediaType'


; 3Com adapters
Case InStr($DeviceID,'3Com')
$Name='media_type'


; HP Realtek adapters
Case InStr($DeviceID,'Realtek')
$Name='DuplexMode'


; Linksys adapters
Case InStr($DeviceID,'Linksys')
$Name='MediaType'


; Virtual WMware ESX Server adapters
Case InStr($DeviceID,'AMD PCNET')
$Name='EXTPHY'


; HP NC3163 adapters
Case InStr($DeviceID,'HP NC3163')
$Name='SpeedDuplex'


; Unable to find one of the listed nic cards
Case 1
$Name = ''
EndSelect


; If we identified the card, read & display the settings
If $Name
; Read the numeric value that represents the current Speed / Duplex setting
$RequestedMediaType = ReadValue($HKLMSCCSCC+'\' + $Key, $Name)


; If this value is blank, we probably don't have a valid NIC definition
; continue if not blank
If $RequestedMediaType <> ''


; Enumerate the values that represent the Speed/Duplex setting descriptions
$Types = ArrayEnumValue($HKLMSCCSCC + '\' + $Key + '\Ndi\params\' + $Name + '\enum')


; Should always be an array ?
If VarType($Types) >= 8192


; Find the descriptive value that matches our defined setting
$Index = AScan($Types, $RequestedMediaType)


; Then get the speed/duplex description string if Index is valid
If $Index >= 0
$Types = $Types[$Index]
$Speed = ReadValue($HKLMSCCSCC+'\' + $Key + '\Ndi\params\' + $Name + '\enum', $Types)
Else
; Value defined does not match avaialble descriptions
$Speed = 'Undetermined'
If $RequestedMediaType = 8 $Speed = 'Possible Gigabit Full Duplex' EndIf
EndIf ; Good index
Else
; Not an array, so no setting names were defined
$Speed = 'Undetermined - bad array'
EndIf ; Is array


'Device Name: ' $DeviceID ?
'Device Index: ' $Key ?
'Speed Setting: ' $Speed ?
'Media Type: ' $RequestedMediaType ?


EndIf ; Requested Media Type


EndIf ; Valid name


EndIf ; Good device id


Next ; Each Entry


; Return an array of subkey names from the primary location
Function ArrayEnumKey($RegSubKey)
Dim $SubKeyCounter, $CurrentSubKey, $SubKeyArray
If Not KeyExist($RegSubKey)
Exit 87
EndIf
$SubKeyCounter = 0
Do
$CurrentSubKey = EnumKey($RegSubKey, $SubKeyCounter)
If Not @ERROR
ReDim Preserve $SubKeyArray[$SubKeyCounter]
$SubKeyArray[$SubKeyCounter] = $CurrentSubKey
$SubKeyCounter = $SubKeyCounter + 1
EndIf
Until @ERROR
$ArrayEnumKey = $SubKeyArray
Exit 0
EndFunction


; Return an array of values from the defined key
Function ArrayEnumValue($RegSubKey)
DIM $ValueCounter, $CurrentValue, $ValueArray
If Not KeyExist($regsubkey)
Exit 87
EndIf
$ValueCounter = 0
Do
$currentvalue=EnumValue($RegSubKey,$ValueCounter)
If Not @ERROR
ReDim Preserve $ValueArray[$ValueCounter]
$ValueArray[$ValueCounter] = $CurrentValue
$ValueCounter = $ValueCounter + 1
EndIf
Until @ERROR
$ArrayEnumValue = $ValueArray
Exit 0
EndFunction




Edited by NTDOC (2005-03-17 09:44 AM)

Top
#135858 - 2005-03-17 06:36 AM Re: Check NicSpeed Script
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Doc,

Made an additional one for our new HP system:
Code:

Case InStr($DeviceID,'Realtek')
$Name='DuplexMode'



Works like a champ!

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#135859 - 2005-03-17 09:46 AM Re: Check NicSpeed Script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Thanks Kent.

I've updated the code above.

1. Added more network card detections
2. Added commenting from Glenn
3. Added support for remote systems

Top
#135860 - 2005-03-18 07:54 AM Re: Check NicSpeed Script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Well Glenn went hog-wild on this and found a better method that eliminates the need to supply names for the NIC or exclude names.

He's has also turned it into a UDF as well.

Working with him to clean up some minor issues still but hopefully will have something to post some time tomorrow on this.

Top
#135861 - 2005-03-18 06:29 PM Re: Check NicSpeed Script
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Doc.. Please let us when. I started the look at this by doing a WMIQuery() and then plugging it into your version.

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#135862 - 2005-03-19 01:49 AM Re: Check NicSpeed Script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Okay, here is a quickie UDF to test it out and provide feedback before Glenn posts it in the UDF forum.

Let us know what you think or any other questions you may have about it.

Code:
Break On
Dim $SO,$Pause
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('WrapAtEOL','On')

Dim $Array, $X, $Y
; Declare the COMPUTER var if not defined on the command line
If Not IsDeclared($COMPUTER)
Global $COMPUTER
EndIf
$Array = NicInfo($COMPUTER)
If UBound($Array) < 0
@SERROR ?
Else
UBound($Array) ' elements returned.' ?
For $X = 0 to UBound($Array)
For $Y = 0 to UBound($Array[$X])
$y '. ' $Array[$X][$Y] ?
Next
Next
EndIf



Code:
;;======================================================================
;;
;;FUNCTION NicInfo()
;;
;;ACTION Returns an array NIC information
;;
;;AUTHOR Glenn Barnas / NTDoc
;;
;;VERSION 1.0
;;
;;DATE CREATED 2005/03/17
;;
;;DATE MODIFIED
;;
;;SYNTAX NicInfo(target)
;;
;;PARAMETERS target - name of sysetm to query
;;
;;REMARKS Array of arrays is returned - a collection of arrays for each physical or virtual NIC
;; WAN/RAS, and Miniport drivers are ignored
;;
;;RETURNS Array of Arrays
;;
;;DEPENDENCIES none
;;
;;TESTED WITH NT4, W2K, WXP
;;
;;EXAMPLES $Array = NicInfo($COMPUTER)
;;
;; If UBound($Array) < 0
;; @SERROR ?
;; Else
;;
;; UBound($Array) ' elements returned.' ?
;;
;; For $X = 0 to UBound($Array)
;; For $Y = 0 to UBound($Array[$X])
;; $y '. ' $Array[$X][$Y] ?
;; Next
;; Next
;; EndIf
;;
;
Function NicInfo(OPTIONAL $Target)

Dim $Regkey, $SubKeyCounter, $NicArray, $CurrentSubKey, $Index
Dim $Name, $Key, $WorkRegKey, $SubKey

; Insure $Target uses the format "\\target\" if specified
$Target = IIf($Target <> '', '\\' + Join(Split($Target, '\'), '', 3) + '\', '')

; Define the primary registry key
$RegKey = $Target + 'HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}'


; init the enumeration index and array index
$SubKeyCounter = 0
$Index = 0


; Enumerate all of the keys that are LAN adapters
$CurrentSubKey = EnumKey($RegKey, $SubKeyCounter)
If @ERROR
Exit @ERROR ; exit now if can't read registry!
EndIf

$CurrentSubKey = EnumKey($RegKey, $SubKeyCounter)
While @ERROR = 0
$Key = ReadValue($RegKey + '\' + $CurrentSubKey, 'Characteristics')
If $Key = 132 Or $Key = 32769 ; physical nic or virtual team
ReDim Preserve $NicArray[$Index] ; increase the array size
$NicArray[$Index] = $CurrentSubKey ; add the subkey to the array
$Index = $Index + 1 ; increment the array index
EndIf
$SubKeyCounter = $SubKeyCounter + 1 ; increment the enumeration index
$CurrentSubKey = EnumKey($RegKey, $SubKeyCounter) ; get the next key
Loop

; Have an array of all the NIC subkeys now... Gather some appropriate data on each
Dim $NicData[UBound($NicArray)]

$Index = 0
Dim $WorkArray[14]
For Each $SubKey In $NicArray
; Start by determining the Speed/Duplex value name
$SubKeyCounter = 0
$Name = ''
$WorkRegKey = $RegKey + '\' + $SubKey + '\Ndi\Params'

; Enumerate all of the subkeys to locate the Speed/Duplex value name
$CurrentSubKey = EnumKey($WorkRegKey, $SubKeyCounter)
While @ERROR = 0 And $Name = ''
$Key = ReadValue($WorkRegKey + '\' + $CurrentSubKey, 'ParamDesc')
If InStr($Key, 'Duplex') Or InStr($Key, 'Connection Type')
$Name = $CurrentSubKey ; Save the Key Name
EndIf
$SubKeyCounter = $SubKeyCounter + 1 ; increment the enumeration index
$CurrentSubKey = EnumKey($WorkRegKey, $SubKeyCounter) ; get the next key
Loop ; enumerate subkeys

; Collect the data for this adapter
$WorkArray[0] = ReadValue($RegKey + '\' + $SubKey, 'DriverDesc') ; Adapter Description
$WorkArray[1] = ReadValue($RegKey + '\' + $SubKey, 'ProviderName') ; Manufacturer
$WorkArray[2] = ReadValue($RegKey + '\' + $SubKey, 'NetCfgInstanceId') ; NIC GUID
$WorkArray[3] = ReadValue($RegKey + '\' + $SubKey, $Name) ; Speed/Duplex value
$WorkArray[4] = ReadValue($WorkRegKey + '\' + $Name + '\Enum', $WorkArray[3]) ; Speed/Duplex text
$WorkArray[5] = ReadValue($RegKey + '\' + $SubKey, 'DriverVersion') ; Driver Version

$WorkRegKey = $Target + 'HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\' + $WorkArray[2]
$WorkArray[6] = ReadValue($WorkRegKey, 'EnableDHCP') ; DHCP boolean
$Key = IIf($WorkArray[6] = 1, 'Dhcp', '')
$WorkArray[7] = ReadStringValue($WorkRegKey, $Key + 'IPAddress') + ',' +
ReadStringValue($WorkRegKey, $Key + 'SubnetMask') + ',' +
ReadStringValue($WorkRegKey, $Key + 'DefaultGateway') ; IP settings
$WorkArray[8] = ReadStringValue($WorkRegKey, $Key + 'Domain') ; Domain Name
$WorkArray[9] = ReadStringValue($WorkRegKey, $Key + 'NameServer') ; DNS Server list

; handle an undefined speed/duplex setting
If $WorkArray[4] = ''
$WorkArray[4] = 'Undefined'
EndIf ; undefined speed

; Special values for Compaq/HP Team
If ReadValue($RegKey + '\' + $SubKey, 'Characteristics') = 32769
$WorkArray[10] = 'HPTEAM' ; special flag
$WorkArray[11] = ReadValue($RegKey + '\' + $SubKey, 'TeamAdapters') ; # of adapters in team
$WorkArray[12] = ReadValue($RegKey + '\' + $SubKey, 'TeamInstances') ; ID of adapters in team
EndIf

$NicData[$Index] = $WorkArray
$Index = $Index + 1

ReDim $WorkArray[14]

Next ; CurrentSubKey

; Return the array of arrays
ReDim Preserve $NicData[$Index - 1]
$NicInfo = $NicData

EndFunction
  
 
; Read a String_Multi_SZ val and return a space-delimited string
Function ReadStringValue($Key, $Val)
$ReadStringValue = Trim(Join(Split(ReadValue($Key, $Val), '|'), ' '))
EndFunction


Top
#135863 - 2005-03-19 02:46 AM Re: Check NicSpeed Script
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
And - the info returned in the sub-array is:

  • Adapter Name
  • Driver vendor
  • NIC GUID
  • Connection Type Value
  • Connection Type Description (ie - 100mb Full Duplex)
  • Driver Version
  • DHCP (boolean)
  • IP Address Info
  • Domain Name
  • Name Servers
  • "HPTeam" when HP/Compaq virtual team is identified
  • # of adapters in team
  • GUIDs of adapters in team


Elements 13/14 do not return anything, and if no further suggestions for information are received, these will be eliminated from the final UDF.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#135864 - 2005-03-23 09:32 PM Re: Check NicSpeed Script
Woodenchef Offline
Fresh Scripter

Registered: 2003-08-29
Posts: 11
doesn't work for me im using kix 4.12 do i need anything else????
Top
#135865 - 2005-03-23 09:36 PM Re: Check NicSpeed Script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yes, at least 4.20
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.153 seconds in which 0.124 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org