CODE@echo off
rem #! /bin/sh
rem edit by stev-o - find the MTU available for current network
rem convert to DOS bat 20090113 mstombs
rem Usage: $0
rem $0 = Me
rem = custom host used for test, different from built-in ones, needed if they go down or close: this is optional
rem .-- Prepare the Command Processor --
setlocal ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSION
rem -- Set the title
set version=01.000
set title=%~nx0 - version %version%
title %title%
::: -- Set the window size --
rem MODE CON: COLS=50 LINES=60
set /a MTU=32
set /a STEP=750
set /a STROKES_LIMIT=30
set /a PACKETS_HEADER=28
set HOST_1=www.google.com
set HOST_2=www.dslreports.com
set HOST_3=www.mozilla.org
set HOST_EXT=%1%
rem Let's start testing, with a small echo-packet, if the host is at least reachable
for %%H in (%HOST_EXT% %HOST_1% %HOST_2% %HOST_3%) do (
ÂÂ set host=%%H
ÂÂ call

robe
ÂÂ if !RESULT! == "0" (
ÂÂ remÂÂIf the 1st host fails, try the others
ÂÂÂÂÂÂset HOSTGOOD="1"
ÂÂÂÂÂÂecho Good, !host! is pingable
ÂÂÂÂÂÂecho.
ÂÂÂÂÂÂgoto got
ÂÂ ) else (
ÂÂÂÂÂÂset HOSTGOOD="0"
ÂÂ )
)
:got
rem No valid hosts founded: exit...
if %HOSTGOOD% NEQ "1" (
ÂÂ echo "No reachable hosts"
ÂÂ pause
ÂÂ exit
)
rem The host is pingable, so let's go on with larger packets....
set /a MTU=STEP
set /a STROKES=0
:do
ÂÂ set /a STEP=STEP-STEP/2
ÂÂ call

robe
ÂÂ if %RESULT% == "0" (
ÂÂÂÂÂÂifÂÂ"%MTU%" == "%MTU_LASTGOOD%" (
ÂÂÂÂÂÂÂÂ goto done
ÂÂÂÂÂÂ) else (
ÂÂÂÂÂÂÂÂ set /a MTU_LASTGOOD=MTU
ÂÂÂÂÂÂÂÂ set /a MTU=MTU+STEP
ÂÂÂÂÂÂ)
ÂÂ ) else (
ÂÂÂÂÂÂset /a MTU=MTU-STEP
ÂÂ )
ÂÂ set /a STROKES=STROKES+1
rem limit the max loop retries in case of successive host failures
if %STROKES% LSS %STROKES_LIMIT% (
ÂÂ goto do
) else (
rem Maximum retries value reached: exit...
ÂÂ echo.
ÂÂ echo "Test limit exceeded"
ÂÂ pause
ÂÂ exit
)
:done
rem Add ICMP default header to the found value
set /a MTU=MTU+PACKETS_HEADER
echo.
echo %MTU_LASTGOOD% bytes is the largest contiguous packet size
echo %MTU% including %PACKETS_HEADER% ICMP/IP Headers
echo.
echo MTU should be set to %MTU%
echo.
pause
exit 0

robe
:: ping host with one icmp-echo packet of variable size
if %host% NEQ "" (
ÂÂ rem #avoid processing NULL, if exthost is not given
ÂÂ echo Sending %MTU% bytes to %host%
ÂÂ ping -f -l %MTU% -n "1" %host% >NUL
ÂÂ rem recursive output message
ÂÂÂÂÂÂif errorlevel 1 (
ÂÂÂÂÂÂÂÂ echo Fragmented
ÂÂÂÂÂÂÂÂ set RESULT="1"
ÂÂÂÂÂÂ) else (
ÂÂÂÂÂÂÂÂ echo Contiguous
ÂÂÂÂÂÂÂÂ set RESULT="0"
ÂÂÂÂÂÂ)
echo.
)
goto:eof