Skip to content

Instantly share code, notes, and snippets.

@agail
Last active October 29, 2020 15:48
Show Gist options
  • Save agail/4c44d6131c27045a67a58c489b116622 to your computer and use it in GitHub Desktop.
Save agail/4c44d6131c27045a67a58c489b116622 to your computer and use it in GitHub Desktop.
simple mac address lookup
@echo off
::
:: description: simple mac address lookup
:: version: 0.6b
::
:: mac address src: https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf
::
setlocal enabledelayedexpansion
set uri=https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf
set macfile=%temp%\mac.txt
call :macfile
set input=%1
if "%input%" == "" goto syntax
if not exist %input% (
set mac=%input%
call :trimmac
call :findmac
goto :eof
)
:: read input file, find dynamic rows
echo.
for /f "tokens=1-4" %%a in ('findstr "DYNAMIC" %input% ^| sort /+25') do call :parse %%a %%b %%c %%d
goto :eof
:: parse dynamic rows
:parse
set mac=%2
call :trimmac
for /f "tokens=3* skip=2" %%x in ('find /i "%mac%" %macfile%') do echo %1 %2 %3 %4 - %%x %%y
)
goto :eof
:findmac
for /f "tokens=3*" %%a in ('find /i "%mac%" %macfile%') do @echo %mac% - %%a %%b
goto :eof
:trimmac
set mac=%mac:-=%
set mac=%mac:.=%
set mac=%mac::=%
set mac=%mac:~0,2%:%mac:~2,2%:%mac:~4,2%
goto :eof
:macfile
if not exist %macfile% (
call :ps-web
) ELSE (
for /f "tokens=1" %%a in ('dir %macfile% ^| findstr /R "....-..-.."') do set fdate=%%a
if not "!fdate!"=="%date%" (
call :ps-web
)
)
goto :eof
:ps-web
powershell -noprofile -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri "%uri:;=`;%" -OutFile "%macfile%""
goto :eof
:syntax
echo.
echo %0 takes one argument, single mac address or input file*.
echo.
echo. mac address: - can be the following formats: 000000000000, 00:00:00:00:00:00, 00-00-00-00-00-00, 0000.0000.0000
echo. input file*: - format of cisco show mac address-table (shown below):
echo.
echo. * if input doesn't exist, we assume it's a mac address
echo.
echo.
echo. Example file: (simply copy/paste into text file, the script looks for DYNAMIC type only)
echo.
echo. Mac Address Table
echo. -------------------------------------------
echo.
echo. Vlan Mac Address Type Ports
echo. ---- ----------- -------- -----
echo. All 0100.0ccc.cccc STATIC CPU
echo. All 0100.0ccc.cccd STATIC CPU
echo. [snip]
echo. All 0180.c200.0010 STATIC CPU
echo. All ffff.ffff.ffff STATIC CPU
echo. 11 0008.2f86.0919 DYNAMIC Gi0/1
echo. 11 0012.7c03.77bf DYNAMIC Fa0/3
echo. 11 0021.7b20.1c79 DYNAMIC Gi0/1
echo. 11 0021.7b20.2337 DYNAMIC Fa0/1
echo. 11 00a0.0308.5ed4 DYNAMIC Gi0/1
echo. 11 4c02.890c.4597 DYNAMIC Gi0/1
echo. 11 5852.8a8c.2bdb DYNAMIC Fa0/4
echo. Total Mac Addresses for this criterion: 27
echo.
endLocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment