Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for mtutest.bat

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

  1. @ECHO OFF
  2. :: Windows NT 4 and later
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4. :: Windows 7 and later
  5. VER | FINDSTR /R /E " 6\.[1-9]\.[0-9][0-9]*\]" >NUL || VER | FINDSTR /R /E " 7\.[0-9]\.[0-9][0-9]*\]" >NUL || GOTO Syntax
  6. :: No command line arguments required
  7. IF NOT "%~1"=="" GOTO Syntax
  8.  
  9. SETLOCAL ENABLEDELAYEDEXPANSION
  10. FOR /F %%A IN ('NETSH interface ipv4 show subinterfaces ^| FINDSTR /R /B /C:"  *[1-9]" ^| FIND /C " "') DO SET Adapters=%%A
  11. IF %Adapters%0 EQU 0 (
  12. 	ECHO No enabled network adapters were detected.
  13. 	EXIT /B 1
  14. )
  15. IF %Adapters%0 NEQ 10 (
  16. 	ECHO This script can only be used with a single network adapter enabled.
  17. 	ECHO A test showed %Adapters% enabled network adapters.
  18. 	ECHO Disable all but one network adapter and try again.
  19. 	EXIT /B %Adapters%
  20. )
  21. SET RC=0
  22. FOR /F "skip=3 tokens=1,4*" %%A IN ('NETSH interface ipv4 show subinterfaces') DO (
  23. 	IF %%A LSS 2000 IF %%A GTR 1000 (
  24. 		SET CurrentMTU=%%A
  25. 		SET Adapter=%%C
  26. 		ECHO Testing network adapter "!Adapter!" . . .
  27. 		SET /A PingSize = !CurrentMTU! - 28
  28. 		PING one.com -f -l !PingSize! 2>NUL | FIND "TTL=" >NUL
  29. 		IF ERRORLEVEL 1 (
  30. 			ECHO The current MTU value for this adapter ^(!CurrentMTU!^) is too high^^!
  31. 			SET RC=1
  32. 		) ELSE (
  33. 			SET /A PingSize = !PingSize! + 10
  34. 			PING one.com -f -l !PingSize! 2>NUL | FIND "TTL=" >NUL
  35. 			IF ERRORLEVEL 1 (
  36. 				ECHO Current MTU value ^(!CurrentMTU!^) is the optimal value for this adapter.
  37. 			) ELSE (
  38. 				ECHO The optimal MTU value for this adapter is higher than the current value ^(!CurrentMTU!^).
  39. 				SET RC=1
  40. 			)
  41. 		)
  42. 	)
  43. )
  44. ENDLOCAL & EXIT /B %RC%
  45.  
  46.  
  47. :Syntax
  48. ECHO.
  49. ECHO MTUTest.bat,  Version 1.00 for Windows 7 and later
  50. ECHO Test if the current MTU value is the optimal value
  51. ECHO.
  52. ECHO Usage:  MTUTEST
  53. ECHO.
  54. ECHO Return value ("errorlevel") will be 0 if MTU value is optimal,
  55. ECHO or 1 otherwise (if not optimal or if an error occurred).
  56. ECHO.
  57. ECHO Based on a tutorial by Harrison Fleetwood:
  58. ECHO http://www.sevenforums.com/tutorials
  59. ECHO /94721-mtu-limit-test-change-your-connection-s-mtu-limit.html
  60. ECHO.
  61. ECHO Written by Rob van der Woude
  62. ECHO http://www.robvanderwoude.com
  63. ECHO.
  64.  
  65. IF "%OS%"=="Windows_NT" EXIT /B 1
  66.  

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