Netzwerk-Tester via CMD
Einfach die folgende Konfiguration als .bat oder .cmd abspeichern und Ihr habt einen einfachen Netzwerk-Tester, der mit Hilfe von dem CDP,HSRP,STP und OSPF Protokoll alle Geräte abfragt welche diese aktiviert haben. Dazu muss nur das richtige Ausgangs-Interface gesetzt sein und schon kann die Suche losgehen.
Bitte die Kommentare beachten.
@if not "%debug%"=="1" echo off
:STARTOVER
setlocal enableextensions
:: set the interface name as it appears in the adapter settings
:: if this is set to nothing (empty), the first non-loopback interface is used
set interf=LAN
if "%1"=="HSRP" (
call :STARTHSRP
exit /b
)
if "%1"=="CDP" (
if exist %temp%\cdp.done del %temp%\cdp.done
call :STARTCDP
exit /b
)
if "%1"=="STP" (
call :STARTSTP
exit /b
)
if "%1"=="OSPF" (
call :STARTOSPF
exit /b
)
echo.
echo.
echo Test Netzwerkverbindung, dies wird bis zu 70 Sekunden dauern...
set timer=060
set GW=Standardgateway
start /b %comspec% /c %0 HSRP
timeout /t 1 >nul
start /b %comspec% /c %0 CDP
timeout /t 1 >nul
start /b %comspec% /c %0 STP
timeout /t 1 >nul
start /b %comspec% /c %0 OSPF
timeout /t 5 >nul
:LOOP
set /a lt+=1
if %lt%==13 goto :ENDLOOP
timeout /t 5 >nul
if not exist %temp%\cdp.done goto :LOOP
:ENDLOOP
echo.
kill tshark.exe >nul 2>nul
timeout /t 3 >nul
copy nul %temp%\\router.temp>nul
if exist %temp%\hsrp.temp for /f "usebackq tokens=1,2" %%i in (%temp%\hsrp.temp) do call :FILTER2 HSRP %%i %%j
if exist %temp%\ospf.temp for /f "usebackq tokens=3" %%i in (%temp%\ospf.temp) do call :FILTER1 OSPF %%i
echo.
echo Gefundene Router
echo ~~~~~~~~~~~~~~~~
more %temp%\router.temp
echo.
set sw=
for /f "usebackq tokens=1-3" %%i in ("%temp%\cdp.temp") do (
if "%%i %%j"=="IP address:" set swip=%%k
if "%%i %%j"=="Device ID:" set sw=%%k
if "%%i %%j"=="Port ID:" set prt=%%k
)
echo.
echo Gefundener Switch
echo ~~~~~~~~~~~~~~~~~
set vlan=
set vlans=
for /f "usebackq tokens=12 delims=/ " %%i in ("%temp%\stp.temp") do (
call :CHKVLAN %%i
)
if "%sw%"=="" (
echo Kein CDP Paket empfangen
) else (
echo %sw% ^(%swip%^)
echo Port %prt%
)
if not "%vlans%"=="" echo VLAN^(s^) %vlans%
:SKIPCDP
echo.
::ipconfig
echo.
echo Verbindungstest
echo ~~~~~~~~~~~~~~~
echo.
for /f "usebackq tokens=1,3" %%i in (`route print`) do (
if "%%i"=="0.0.0.0" call :PINGGW %%j
)
::del %temp%\cdp.temp
del %temp%\cdp.done
del %temp%\hsrp.temp
del %temp%\ospf.temp
del %temp%\stp.temp
del %temp%\router.temp
goto ENDE
:PINGGW
if "%1" == "" goto :EOF
ping -n 1 -w 2 %1 >nul 2>nul
if %errorlevel% == 0 (
echo Default-Gateway %1 : OK
) else echo Default-Gateway %1 : Keine Verbindung
goto :EOF
:FILTER1
find "%2 (%1)" %temp%\router.temp>nul
if "%errorlevel%"=="1" echo %2 (%1)>>%temp%\router.temp
goto :EOF
:FILTER2
find "%2 (%1 %3)" %temp%\router.temp>nul
if "%errorlevel%"=="1" echo %2 (%1 %3)>>%temp%\router.temp
goto :EOF
:CHKVLAN
if "%vlan%"=="" set vlan=#%1#
if "%vlans%"=="" set vlans=%1
echo %vlan% | find "#%1#" >nul
if %errorlevel%==1 (
set vlan=%vlan%,#%1#
set vlans=%vlans%,%1
)
goto :EOF
:STARTOSPF
tshark.exe -f "ip proto 89" -a duration:%timer% %interf% -l >%temp%\ospf.temp 2>nul
exit /b
goto :EOF
:STARTHSRP
tshark.exe -f "(ether dst 01:00:5e:00:00:02 || ether dst 01:00:5e:00:00:66) && udp port 1985" -Tfields -e ip.src -e hsrp.virt_ip -e hsrp2.virt_ip -a duration:%timer% -i "%interf%" -l >%temp%\hsrp.temp 2>nul
exit /b
goto :EOF
:STARTSTP
tshark.exe -f "ether dst 01:80:c2:00:00:00 || 01-00-0C-CC-CC-CD" -a duration:%timer% -i "%interf%" -Ttext -l >%temp%\stp.temp 2>nul
exit /b
goto :EOF
:STARTCDP
tshark.exe -f "ether dst 01:00:0c:cc:cc:cc and ether[16:4] = 0x0300000C and ether[20:2] == 0x2000" -a duration:%timer% -c 1 -i "%interf%" -Ttext -l -V>%temp%\cdp.temp 2>nul
echo done >%temp%\cdp.done
exit /b
goto :EOF
:EXEC
%*
goto :EOF
:ENDE
endlocal
echo.
echo Eine Taste druecken, um den Test erneut auszufuehren
pause >nul
echo.
echo -------------------------------------------------------------------------
goto :STARTOVER

Let's go and write a comment