如何通过 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 中使用批处理文件来执行此操作。谢谢。
I'm trying to write a script that will compare the MAC address of Local Area Connection to the MAC address in software licenses to see if one of the licenses matches the machines. The part that has me stuck right now is pulling the MAC address of a specific device "Local Area Connection".
I have tried using search features such as:
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
I really don't need the echo in the above attempt, but I use it for debugging.
But still the above statement puts text into a file like this:
"Physical Address. . . . . . . . . : 00-37-10-D1-98-2C
Ethernet adapter Local Area Connection:
Physical Address. . . . . . . . . : 5D-26-0A-11-11-15"
(quotes added by me to show the beginning and end of text file)
From that, I'm not sure how to pull the MAC address that comes after Ethernet adapter Local Area Connection, especially when they're not on the same line.
I need to do this with a batch file in Windows XP Professional. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个旧脚本应该可以工作。
它首先搜索正确的适配器,然后等待包含字符串“Physical”的行。
:Normalize 函数用于删除 < XP 系统中 ipconfig 的输出中存在回车符>,因为微软并不确切知道一行应该以 CR/LF 结尾,而不是以 LF/CR 结尾。
This old script should work.
It searches first for the correct adapter, and then it waits until a line containing the string "Physical".
The :Normalize function is for removing < Carriage Return> in the output of ipconfig at XP systems, as microsoft doesn't know exactly that a line should end with CR/LF not with LF/CR.