BAT批處理獲取IP、MAC
阿新 • • 發佈:2019-01-11
@echo off & setlocal enabledelayedexpansion echo =-----------------------------------------= echo = 本BAT只列出一個有線和一個無線的IP資訊 = echo = 讀取資訊請耐心等待 = echo =-----------------------------------------= echo loding... for /f "tokens=1 delims=[]" %%i in ('nbtstat -S^|find /n "本地連線:"') do ( nbtstat -S | more +%%i >$ set /p Str=<$ del $ for /f "tokens=2 delims=[]" %%i in ('echo "!Str!"') do set LIP=%%i ) for /f "tokens=1 delims=[]" %%i in ('nbtstat -S^|find /n "無線網路連線:"') do ( nbtstat -S | more +%%i >$ set /p Str=<$ del $ for /f "tokens=2 delims=[]" %%i in ('echo "!Str!"') do set WIP=%%i ) for /f "tokens=16" %%i in ('ipconfig /all ^| find /i "IPv4 地址"') do set ip=%%i echo 本機使用者名稱為: %COMPUTERNAME% echo 本機有線IP為:%LIP% echo 本機無線IP為:%WIP% echo 本機首選IP為:%ip% echo 本機實體地址:loding... echo =================================================== @echo off for /f "tokens=1,3 delims=," %%i in ('getmac /v /nh /fo:csv ^| findstr "..-..-..-..-..-.."') do ( echo %%i %%j ) echo =================================================== echo 當前時間:%DATE% echo by forlin echo =================================================== pause
單獨獲取MAC
for /f %%i in ('getmac /nh ^| findstr "..-..-..-..-..-.."') do set mac=%%i
注意:
匹配的字元段請按實際來,比如WIN7是“IPv4 地址”,其它系統可能就不是這個了,你可以先開啟CMD輸入ipconfig檢視
nbtstat 命令