如何通过Windows批处理文件找到特定设备的MAC地址?

| 我正在尝试编写一个脚本,将本地连接的MAC地址与软件许可证中的MAC地址进行比较,以查看其中一个许可证是否与计算机匹配。我现在遇到的问题是提取特定设备的MAC地址“本地连接”。 我尝试使用搜索功能,例如:
ipconfig /all | findstr^ /C:\"Local Area Connection\"^ /C:\"Physical Address\" > C:\\temp\\macaddress.txt
for /f \"tokens=1,2 delims=:\" %%i in (C:\\temp\\macaddress.txt) do @echo The MAC Address of %%i is %%j
pause
在上面的尝试中,我确实不需要回显,但是我将其用于调试。 但是上面的语句仍然将文本放入这样的文件中: \“物理地址........:00-37-10-D1-98-2C 以太网适配器本地连接: 实际地址。 。 。 。 。 。 。 。 。 :5D-26-0A-11-11-15 \“ (我添加的引号表示文本文件的开头和结尾) 由此,我不确定如何提取以太网适配器本地连接后的MAC地址,尤其是当它们不在同一行时。 我需要使用Windows XP Professional中的批处理文件来执行此操作。谢谢。     
已邀请:
这个旧脚本应该可以工作。 它首先搜索正确的适配器,然后等待直到包含字符串“物理”的行。 :Normalize函数用于在XP系统上的ipconfig输出中删除<回车>,因为Microsoft并不完全知道一行应以CR / LF结尾而不是LF / CR。
@echo off
SETLOCAL EnableDelayedExpansion EnableExtensions

rem call :GetIP ip_WLAN \"Drahtlos\"
rem echo ---
set OS_Version=XP
call :GetIP result  \"Ethernet adapter\" \"Physical\"

echo mac=%result%

goto :eof

::::::::::::::::::::::::::::
:GetIP <resultVar> <AdapterName>
:: resultVar    return variable for the searched value
:: AdapterName  part of the adapter name
setlocal
set /a found=0
if \"%OS_Version%\"==\"Win7\" set ipText=IPv4
if \"%OS_Version%\"==\"Vista\" set ipText=IPv4
if \"%OS_Version%\"==\"XP\" set ipText=IP-
if \"%~3\"==\"\" (
    set searchText=!ipText!
) ELSE (
    set \"searchText=%~3\"
)
for /F \"tokens=1,* delims=:\" %%a IN (\'ipconfig /all\') DO (  
  call :Normalize first \"%%a.dummy\"
  call :Normalize post \"%%b.dummy\"

  if \"!post!\"==\"_\" (
    if \"!first:%~2=!\" NEQ \"!first!\" (
        set /a found=1
        rem echo adapter found \"!first!\"
    ) ELSE (
        if \"!first!\" NEQ \"_\" (
            set /a found=0
            rem echo - !first! !post!
        )
    )
  )

  if !found! EQU 1 (
    rem echo try \"!first!\"
    if \"!first:%searchText%=!\" NEQ \"!first!\" (
        set ipAddr=!post:_=!
        set ipAddr=!ipAddr: =!
        rem echo IP found !post! for adapter
    )
  )
)

(
  endlocal
  set %~1=%ipAddr%
  goto :eof
)

:Normalize
set %~1=_%~n2
goto :eof
    

要回复问题请先登录注册