中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-02 07:10
48,037 topics / 350,122 posts / today 2 new / 48,250 members
DOS批处理 & 脚本技术(批处理室) » A batch script bound to IP
Printable Version  1,441 / 2
Floor1 txysz Posted 2006-09-29 22:43
新手上路 Posts 2 Credits 8
@echo off
if exist ipconfig.txt del ipconfig.txt
ipconfig /all >ipconfig.txt
if exist phyaddr.txt del phyaddr.txt
find "Physical Address" ipconfig.txt >phyaddr.txt
for /f "skip=2 tokens=12" %%M in (phyaddr.txt) do set Mac=%%M
This part means: Skip the first 2 lines, then take the 12th token, and assign it to the variable Mac.
if exist IPAddr.txt del IPaddr.txt
find "IP Address" ipconfig.txt >IPAddr.txt
for /f "skip=2 tokens=15" %%I in (IPAddr.txt) do set IP=%%I
arp -s %IP% %Mac%
if exist GateIP.txt del GateIP.txt
find "Default Gateway" ipconfig.txt >GateIP.txt
for /f "skip=2 tokens=13" %%G in (GateIP.txt) do set GateIP=%%G
if exist GateMac.txt del GateMac.txt
arp -a %GateIP% >GateMac.txt
for /f "skip=3 tokens=2" %%H in (GateMac.txt) do set GateMac=%%H
arp -s 192.168.0.1 00-05-5d-a1-c2-76
exit

Is there any expert who can explain what it means, especially the part of %%M, I don't understand it.
Floor2 lxmxn Posted 2006-09-29 23:00
版主 Posts 4,938 Credits 11,386
The following is the translation:

for /f "skip=2 tokens=12" %%M in (phyaddr.txt) do set Mac=%%M

Among them, %%M is a variable representing the value extracted by the for statement. When you need to use this value later, you can directly call %%M. This sentence means: In the phyaddr.txt file, skip the first two lines and extract the content of the 12th column. Then assign the value of the variable %%M to Mac. (I don't know if the above batch processing can extract the MAC address, I can't extract it.)
Floor3 txysz Posted 2006-10-01 20:49
新手上路 Posts 2 Credits 8
Found some tutorials, but didn't see what %%M means in for. Now I understand.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023