Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for nicspeed.bat

(view source code of nicspeed.bat as plain text)

  1. @ECHO OFF
  2. :: Check Windows version
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4.  
  5. :: First command line check
  6. IF NOT "%~2"=="" GOTO Syntax
  7.  
  8. :: Thorough command line check
  9. ECHO.%~1| FINDSTR /R /B /I /C:"[A-Z0-9_-]*$" >NUL
  10. IF ERRORLEVEL 1 GOTO Syntax
  11.  
  12. :: Proceed
  13. SETLOCAL ENABLEDELAYEDEXPANSION
  14.  
  15. :: Determine name of computer to be investigated
  16. IF "%~1"=="" (
  17. 	SET Computer=%ComputerName%
  18. ) ELSE (
  19. 	SET Computer=%~1
  20. )
  21.  
  22. :: Find the network adapter link speed
  23. FOR /F "tokens=1* delims==" %%A IN ('WMIC.EXE /Node:"%Computer%" /NameSpace:\\root\WMI Path MSNdis_EthernetCurrentAddress Where "Active='TRUE'" Get InstanceName /Format:LIST ^| FIND "="') DO (
  24. 	REM * * * * * *  Chomp off the trailing CR/LF  * * * * * *
  25. 	FOR /F "tokens=*" %%C IN ("%%~B") DO (
  26. 		FOR /F "tokens=1* delims==" %%D IN ('WMIC.EXE /Node:"%Computer%" /NameSpace:\\root\CIMV2 Path Win32_NetworkAdapter Where "(AdapterTypeId='0' And Name='%%~C' And PhysicalAdapter='TRUE')" Get Name /Format:LIST 2^>NUL ^| FIND "="') DO (
  27. 			REM * * * * * *  Chomp off the trailing CR/LF  * * * * * *
  28. 			FOR /F "tokens=*" %%F IN ("%%~E") DO (
  29. 				FOR /F "tokens=1* delims==" %%G IN ('WMIC.EXE /Node:"%Computer%" /NameSpace:\\root\CIMV2 Path Win32_NetworkAdapter Where "(Name='%%~F' And PhysicalAdapter='TRUE' And AdapterTypeId=0)" Get Name /Format:LIST 2^>NUL ^| FIND "="') DO (
  30. 					REM * * * * * *  Chomp off the trailing CR/LF  * * * * * *
  31. 					FOR /F "tokens=*" %%I IN ("%%~H") DO (
  32. 						SET InstanceName=
  33. 						SET NdisLinkSpeed=
  34. 						SET Multiplier=k
  35. 						FOR /F "tokens=*" %%J IN ('WMIC.EXE /Node:"%Computer%" /NameSpace:\\root\WMI Path MSNdis_LinkSpeed Where "InstanceName='%%~I'" Get InstanceName^,NdisLinkSpeed /Format:LIST 2^>NUL ^| FIND "="') DO (
  36. 							REM * * * * * *  Chomp off the trailing CR/LF  * * * * * *
  37. 							FOR /F "tokens=*" %%K IN ("%%~J") DO (
  38. 								SET %%K
  39. 							)
  40. 						)
  41. 						REM * * * * * *  If over 1000 kb/s display in Mb/s  * * * * * *
  42. 						IF !NdisLinkSpeed! GTR 1000 (
  43. 							SET /A NdisLinkSpeed = !NdisLinkSpeed! + 500
  44. 							SET /A NdisLinkSpeed = !NdisLinkSpeed! / 1000
  45. 							SET Multiplier=M
  46. 						)
  47. 						REM * * * * * *  If over 1000 Mb/s display in Gb/s  * * * * * *
  48. 						IF !NdisLinkSpeed! GTR 1000 (
  49. 							SET /A NdisLinkSpeed = !NdisLinkSpeed! + 500
  50. 							SET /A NdisLinkSpeed = !NdisLinkSpeed! / 1000
  51. 							SET Multiplier=G
  52. 						)
  53. 						REM * * * * * *  Display results  * * * * * *
  54. 						ECHO NIC   : !InstanceName!
  55. 						ECHO Speed : !NdisLinkSpeed! !Multiplier!b/s
  56. 						ECHO.
  57. 					)
  58. 				)
  59. 			)
  60. 		)
  61. 	)
  62. )
  63.  
  64. ENDLOCAL
  65. GOTO:EOF
  66.  
  67.  
  68. :Syntax
  69. ECHO.
  70. ECHO NICSpeed.bat,  Version 1.00 for Windows XP Professional and later
  71. ECHO Display active Ethernet adapters' link speed
  72. ECHO.
  73. ECHO Usage:  NICSPEED.BAT  [ remote_computer ]
  74. ECHO.
  75. ECHO Written by Rob van der Woude
  76. ECHO http://www.robvanderwoude.com
  77.  

page last modified: 2024-04-16; loaded in 0.0062 seconds