设定静态arp脚本(bat)

@echo OFF
arp -d
if %~n0==arp exit
if %~n0==Arp exit
if %~n0==ARP exit
echo 正在获取本机信息…..
echo 本脚本适用windows2003,单网卡,单路由,设定静态arp用
echo 其它情况不适用,需修改参数

:IP
FOR /f "skip=13 tokens=15 usebackq " %%i in (`ipconfig /all`) do Set IP=%%i && GOTO MAC
REM 在ipconfig命令的结果中,跳到13行,第15个字符 取本机ip值赋予ip变量
:MAC
echo 取得IP:%IP%
FOR /f "skip=13 tokens=12 usebackq " %%i in (`ipconfig /all`) do Set MAC=%%i && GOTO GateIP
REM 取得本机mac值赋予mac变量

:GateIP
echo 取得MAC:%MAC%
arp -s %IP% %MAC%
REM 设定本机静态arp

echo 正在获取网关信息…..
FOR /f "skip=17 tokens=13 usebackq " %%i in (`ipconfig /all`) do Set GateIP=%%i && GOTO GateMac
REM 取得网关ip值赋予gateip变量

:GateMac
echo GateIP:%GateIP%
ping %GateIP% -t -n 1
FOR /f "skip=3 tokens=2 usebackq " %%i in (`arp -a %GateIP%`) do Set GateMAC=%%i && GOTO Start
REM 取得网关mac值赋予gatemac变量

:Start
echo GateMAC:%GateMAC%
arp -s %GateIP% %GateMAC%
@pause
echo 操作完成!!!