绑定IP和MAC方法

方法1:
echo off
:::::::::读取本机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%
:::::::::读取网关地址
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
ping %GateIP% -n 1
:::::::::读取网关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
:::::::::绑定网关Mac和IP
arp -s %GateIP% %GateMac%
:::::::::删除临时文件
del GateIP.txt
del GateMac.txt
del IPAddr.txt
del ipconfig.txt
del phyaddr.txt
 
 
方法2:
@echo off
for /f "tokens=1* delims=:" %%i in ('ipconfig /all^|find /i "Physical Address"') do set mac=%%j
for /f "tokens=1* delims=:" %%i in ('ipconfig /all^|find /i "IP Address"') do set ip=%%j
for /f "tokens=1* delims=:" %%i in ('ipconfig /all^|find /i "Default Gateway"') do set gip=%%j
arp -d
ping %gip% /n 1 >nul
for /f "skip=3 tokens=2" %%i in ('arp -a %gip:~1%') do set gmac=%%i
arp -s %ip:~1% %Mac:~1%
arp -s %gip:~1%  %gmac:~1%
exit
 
方法3:
@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
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

exit
 
 
 
以上三种方法个人建议使用一种,建立BAT批处理放置WINDOWS系统启动项,每次启动会自动绑定一次。
 
 
 

你可能感兴趣的:(职场,休闲,网络[ARP])