windows 批处理 多网卡时 获取电脑mac地址(物理地址)脚本

原理:

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

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值