windows cmd check mac address

Check if a mac address exists

 

********** final get router mac address ********

for /f "tokens=1,* delims=:" %a in ('ipconfig ^| findstr /IR "default gateway" ^| findstr ".*[0-9]"') do set _gateway=%b
set _gateway=%_gateway: =%
for /f "tokens=1,* delims= " %a in ('arp -a %_gateway%') do set _gatemac=%b
set _gatemac=%_gatemac: dynamic=%
echo %_gatemac%

********** final get router mac address for batch file ********

for /f "tokens=1,* delims=:" %%a in ('ipconfig ^| findstr /IR "default gateway" ^| findstr ".*[0-9]"') do set _gateway=%%b
set _gateway=%_gateway: =%
for /f "tokens=1,* delims= " %%a in ('arp -a %_gateway%') do set _gatemac=%%b
set _gatemac=%_gatemac: dynamic=%
echo %_gatemac%
pause

**********

********** final get router mac address for batch file and take action ********

rem findmac.bat

rem If router mac changes then restart vpn
rem if router mac is in office then kill vpn

@echo off

set batchdir=%~dp0
echo %_gatemac% > "%batchdir%\getemac.txt"

call:while1

:while1
call:chkMacFunc
timeout 5
goto :while1

:chkMacFunc
call:getMacFunc
set _match=0
set _office=0
set /p _oldgatemac=<"%batchdir%\getemac.txt"
if not %_gatemac% == %_oldgatemac% (Taskkill /IM ipsecc.exe) &  (echo %_gatemac% > "%batchdir%\getemac.txt") & echo new mac restart shrew vnc
if %_gatemac% == 00-1d-aa-fc-e5-10 (Taskkill /IM ipsecc.exe) & echo mac matches so kill ipsecc.exe
goto:eof

:getMacFunc
for /f "tokens=1,* delims=:" %%a in ('ipconfig ^| findstr /IR "default gateway" ^| findstr ".*[0-9]"') do set _gateway=%%b
set _gateway=%_gateway: =%
for /f "tokens=1,* delims= " %%a in ('arp -a %_gateway%') do set _gatemac=%%b
set _gatemac=%_gatemac: dynamic=%
goto:eof

**********