@echo off :::::::::::::::::::::::::::::::::::::::::::::::::::: : 本機以及網(wǎng)關(guān)IP和MAC地址綁定批處理程序:: :::::::::::::::::::::::::::::::::::::::::::::::::::: arp -d :::::::::讀取本機Mac地址 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 :::::::::讀取本機ip地址 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 :::::::::綁定本機IP地址和MAC地址 arp -s %IP% %Mac% :::::::::讀取網(wǎng)關(guān)地址 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 :::::::::獲取網(wǎng)關(guān)MAC地址 ping 192.168.0.1 -n 1 :::::::::讀取網(wǎng)關(guān)Mac地址 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 :::::::::綁定網(wǎng)關(guān)Mac和IP arp -s %GateIP% %GateMac% del GateIP.txt del GateMac.txt del IPAddr.txt del ipconfig.txt del phyaddr.txt exit