原理:
1.首选网卡一般名称叫“以太网适配器”,我们主要想获取这块网卡的物理地址和IP地址
2.通过ipconfig /all,然后通过for循环定位到“以太网适配器”配置信息开始的行
3.然后逐步获取信息,直到获取到ipv4的地址为止,此过程中会同时获取到“物理地址”
4.通过findstr 过滤需要的信息
@echo off
cd /d %~dp0
echo loading...
set filename=info.txt
hostname > info.txt
echo "" > infoTmp.txt
set DstCard=以太网适配器
ipconfig /all>"%temp%\ipList.txt"
for /f "tokens=1 delims=:" %%a in ('findstr /n "%DstCard%" "%temp%\ipList.txt"') do (
set ipRow=%%a
goto :RowCount
)
:RowCount
set /a dstRow=ipRow
for /f "usebackq skip=%dstRow% tokens=1,2 delims=:" %%a in ("%temp%\ipList.txt") do (
echo %%a %%b >> infoTmp.txt
if "%%a" equ " IPv4 地址 . . . . . . . . . . . . " (
goto :ShowResult
)
)
:ShowResult
findstr IPv4 infoTmp.txt >> info.txt
findstr 物理地址 infoTmp.txt >> info.txt
start info.txt
pause