标题: IP绑定求解
[打印本页]
作者: ask
时间: 2008-7-5 14:22
标题: IP绑定求解
高手帮忙分析下下面这个批处,最好能详细点,我刚学的,里面有些地方不是很懂
如:for /f "skip=2 tokens=15" %%I in (IPAddr.txt) do set IP=%%I
还有这个arparp是什么命令来着,dos下查不出来,还有%GateIP%这里前后转义的用法有什么作用?谢谢!!~~~~
@echo off
ping 202.96.134.134 -n 1
if exist ipconfig.txt del ipconfig.txt
ipconfig /all >c:\ipconfig.txt
if exist phyaddr.txt del phyaddr.txt
find "Physical Address" ipconfig.txt >c:\phyaddr.txt
for /f "skip=2 tokens=12" %%M in (phyaddr.txt) do set Mac=%%M
if exist IPAddr.txt del IPaddr.txt
find "IP Address" ipconfig.txt >c:\IPAddr.txt
for /f "skip=2 tokens=15" %%I in (IPAddr.txt) do set IP=%%I
arparp -s %IP% %Mac%
@echo off
if exist GateIP.txt del GateIP.txt
find "Default Gateway" ipconfig.txt >c:\GateIP.txt
for /f "skip=2 tokens=13" %%G in (GateIP.txt) do set GateIP=%%G
if exist GateMac.txt del GateMac.txt
arparp -a %GateIP% >c:\GateMac.txt
for /f "skip=3 tokens=2" %%H in (GateMac.txt) do set GateMac=%%H
arparp -s %GateIP% %GateMac%
exit
作者: bat-zw
时间: 2008-7-5 15:05
楼主在网上找来的这段代码实在太垃圾了,也就没必要给楼主详细说明了,如楼主要自动绑定ip和mac,我下面的这段代码还行(兼容多网卡):
@echo off&setlocal enabledelayedexpansion
for /f "tokens=2 delims=:" %%i in ('ipconfig /all^|findstr /c:"Physical Address"')do (
set /a n+=1,m=0
set str=%%i&set str=!str:~1!&call :lp
)
echo 搞定!
pause>nul&goto :eof
:lp
for /f "tokens=2 delims=:" %%i in ('ipconfig /all^|findstr /c:"IP Address"') do (
set /a m+=1
if !m! equ %n% (
set var=%%i&set var=!var:~1!
arp -s !var! !str!
)
)
[
Last edited by zw19750516 on 2008-7-5 at 03:21 PM ]
作者: ask
时间: 2008-7-6 14:02
很感谢zw19750516提供代码,只是我是初学,很多地方不是很懂,那段代码是网吧用的,我拿来琢磨,所以发来想让大家帮忙分析下!
for /f "skip=2 tokens=12" %%M in (phyaddr.txt) do set Mac=%%M
主要是上面这句的用法弄不清楚,小弟在这先谢过了~~~!!!
作者: bat-zw
时间: 2008-7-6 18:54
for /f "skip=2 tokens=12" %%M in (phyaddr.txt) do set Mac=%%M
这句的意思是将phyaddr.txt文本中第三行第12列(以空格为间隔符)的字符串赋值给变量mac。
作者: ask
时间: 2008-7-11 14:14
作者: pusofalse
时间: 2008-7-11 14:16
跳过前两行。。。。
多看下for/?的帮助,会有收获
作者: dos9527
时间: 2008-7-11 16:36
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
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%
del ipaddr.txt
del ipconfig.txt
del phyaddr.txt