桌面新建txt文件,将代码复制后另存为bat文件,另存为时编码改为ANSI:
@echo off & setlocal enabledelayedexpansion echo=-----------------------------------------=echo= 本BAT只列出一个有线和一个无线的IP信息 =echo= 读取信息请耐心等待 =echo=-----------------------------------------=echo.for /f "tokens=1 delims=[]" %%i in ('%SystemRoot%\system32\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 ('%SystemRoot%\system32\nbtstat -S^|find /n "WLAN:"') 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 =================================================== >%tmp%\ip-mac.txtecho 当前时间:%DATE% >>%tmp%\ip-mac.txtecho =================================================== >>%tmp%\ip-mac.txtecho 本机用户名为:%COMPUTERNAME% >>%tmp%\ip-mac.txtecho 本机有线IP为:%LIP% >>%tmp%\ip-mac.txtecho 本机无线IP为:%WIP% >>%tmp%\ip-mac.txt::echo 本机首选IP为:%ip% >>%tmp%\ip-mac.txtecho 本机物理地址: >>%tmp%\ip-mac.txtecho ===================================================for /f "tokens=1,3 delims=," %%i in ('getmac /v /nh /fo:csv ^| findstr"..-..-..-..-..-.."') do (echo %%i %%j >>%tmp%\ip-mac.txt) echo =================================================== >>%tmp%\ip-mac.txtipconfig | findstr /i "以太网 无线 IPv4">>%tmp%\ip-mac.txtStart %tmp%\ip-mac.txt
转自:批处理获取本机IP地址及MAC地址,输出到文件 - 简书 ()