-
- ::==================IP绑定MAC(本机和网关)==============
- ::code by youxi01@bbs.bathome.net 2008-1-6
- ::优点:不产生临时文件、速度较快;
- ::缺点:可能不支持多网卡
- @echo off & setlocal enabledelayedexpansion
- title IP绑定MAC(本机和网关)@bbs.bathome.net
- Rem '/*===========设置要提取的字符串===========*/
- set "IP_addr=IP Address"
- set "MAC_addr=Physical Address"
- set "GW_addr=Default Gateway"
- for /f "delims=. tokens=1,*" %%i in ('ipconfig /all') do (
- Rem '/*=========下面这行是去掉字符串两端的空格=======*/
- for /f "tokens=*" %%a in ("%%i") do set "var=%%~nxa"
- for %%a in (IP_addr MAC_addr GW_addr) do (
- if "!%%a!"=="!var!" (
- set %%a=%%j
- )
- )
- )
- arp -s %IP_addr:*:=% %MAC_addr:*:=%
- for /f "skip=3 tokens=2" %%i in ('arp -a %GW_addr:*:=%') do set GW_MAC=%%i
- arp -s %GW_addr:*:=% %GW_MAC%
-
- pause>nul
-
复制代码
|