China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-02 06:01
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » A batch script bound to IP View 1,439 Replies 2
Original Poster Posted 2006-09-29 22:43 ·  中国 广东 深圳 南山区 电信
新手上路
Credits 8
Posts 2
Joined 2006-09-28 02:05
19-year member
UID 63860
Gender Male
Status Offline
@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.
Floor 2 Posted 2006-09-29 23:00 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
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.)
Floor 3 Posted 2006-10-01 20:49 ·  中国 广东 深圳 南山区 电信
新手上路
Credits 8
Posts 2
Joined 2006-09-28 02:05
19-year member
UID 63860
Gender Male
Status Offline
Found some tutorials, but didn't see what %%M means in for. Now I understand.
Forum Jump: