Created
March 4, 2013 21:45
-
-
Save vovcacik/5085969 to your computer and use it in GitHub Desktop.
A batch file that finds out the maximum MTU between local and specified remote host using plain ping command.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
rem This batch will find out maximum MTU between local and remote host. | |
SetLocal EnableDelayedExpansion | |
set MTU=1473 | |
set LASTGOOD=0 | |
set LASTBAD=65536 | |
set PACKETSIZE=28 | |
set SERVER= | |
rem Check presence of target parameter. | |
if "%~1" EQU "" ( | |
echo. | |
echo Usage: mtu IPv4 ^| hostname | |
echo. | |
echo On success the result is assigned to %%MAXMTU%% variable | |
echo and %%ErrorLevel%% is set to 0. On error the %%MAXMTU%% | |
echo variable is set to -1 value and %%ErrorLevel%% is set to | |
echo non-zero value. | |
goto :error | |
) else ( | |
set SERVER=%~1 | |
) | |
rem Check server reachability. | |
ping -n 1 -l 0 -f -4 !SERVER! 1>nul | |
if !ERRORLEVEL! NEQ 0 ( | |
echo Error: cannot ping !SERVER!. Run "ping -n 1 -l 0 -f -4 !SERVER!" to see details. | |
goto :error | |
) | |
:seek | |
rem Start looking for the maximum MTU. | |
ping -n 1 -l !MTU! -f -4 !SERVER! 1>nul | |
if !ERRORLEVEL! EQU 0 ( | |
set /A LASTGOOD=!MTU! | |
set /A "MTU=(!MTU! + !LASTBAD!) / 2" | |
if !MTU! NEQ !LASTGOOD! goto :seek | |
) else ( | |
set /A LASTBAD=!MTU! | |
set /A "MTU=(!MTU! + !LASTGOOD!) / 2" | |
if !MTU! NEQ !LASTBAD! goto :seek | |
) | |
rem Print the result. | |
set /A "MAXMTU=!LASTGOOD! + !PACKETSIZE!" | |
echo Maximum MTU for !SERVER!: !MAXMTU! bytes. | |
rem Export %MAXMTU% variable. | |
EndLocal & set MAXMTU=%MAXMTU% | |
exit /B 0 | |
:error | |
rem When something unexpected occurs. | |
EndLocal & set MAXMTU=-1 | |
exit /B 1 |
На windows 10 не работает... :(
I am on Windows 10 Pro v1607 and it works here. With debugging enabled:
C:\Users\Admin\Desktop>mtu.bat 192.168.1.1
ping -n 1 -l 1473 -f -4 192.168.1.1
ping -n 1 -l 736 -f -4 192.168.1.1
ping -n 1 -l 1104 -f -4 192.168.1.1
ping -n 1 -l 1288 -f -4 192.168.1.1
ping -n 1 -l 1380 -f -4 192.168.1.1
ping -n 1 -l 1426 -f -4 192.168.1.1
ping -n 1 -l 1449 -f -4 192.168.1.1
ping -n 1 -l 1461 -f -4 192.168.1.1
ping -n 1 -l 1467 -f -4 192.168.1.1
ping -n 1 -l 1470 -f -4 192.168.1.1
ping -n 1 -l 1471 -f -4 192.168.1.1
ping -n 1 -l 1472 -f -4 192.168.1.1
Maximum MTU for 192.168.1.1: 1500 bytes.
У меня Windows 10 Pro 20H2, как включить режим отладки для консоли?
Запускаю батник - он тут же закрывается.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
На windows 10 не работает... :(