zoukankan      html  css  js  c++  java
  • Windows脚本 关于本机ARP静态绑定批处理文件讲解[绑定ipmac脚本详解]

    http://www.x5dj.com/Blog/00534041/00389986.shtml

    原批处理文件如下:

    @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

    现在以//开头的为我的解释

    @echo off
    //关闭命令回显

    if exist ipconfig.txt del ipconfig.txt
    //如果存在 ipconfig.txt 这个文件就对其进行删除 

    ipconfig /all >ipconfig.txt
    //把 ipconfig /all 命令的显示结果写入 ipconfig.txt

    if exist phyaddr.txt del phyaddr.txt
    //如果存在 phyaddr.txt 这个文件就对其进行删除

    find "Physical Address" ipconfig.txt >phyaddr.txt
    //在 ipconfig.txt 文件里查找 Physical Address 字段的内容并将其字段内容写入 phyaddr.txt

    for /f "skip=2 tokens=12" %%M in (phyaddr.txt) do set Mac=%%M
    //在 phyaddr.txt 文件中从第一行象下跳两行,也就是从第三行开始,从第12个符号处取值,并把该值设置成 MAC 变量,举个例子:Physical Address. . . . . . . . . : 00-E0-FC-0C-A8-4F,每一个连续的数值为一个符号
    符号1:Physical
    符号2:Address.
    符号3:.
    符号4:.
    符号5:.
    符号6:.
    符号7:.
    符号8:.
    符号9:.
    符号10:.
    符号11::
    符号12:00-E0-FC-0C-A8-4F
    tokens=12 的意思现在大家该明白了吧,但是说明一点,FOR 命令中的变量在批处理中是用 %%X 表示,但是在 命令提示符 下输入却是用 %X 表示的,切记

    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
    //这几句还看不懂的话就未免太``````
    上面的脚本是绑定本机IP和MAC的。
    下面的是绑定 网关IP和MAC的。
     
    @echo OFF
    if %~n0==arp exit
    if %~n0==Arp exit
    if %~n0==ARP exit
    echo 正在获取本机信息.....
    :IP
    FOR /f "skip=13 tokens=15 usebackq " %%i in (`ipconfig /all`) do Set IP=%%i && GOTO MAC
    :MAC
    echo IP:%IP%
    FOR /f "skip=13 tokens=12 usebackq " %%i in (`ipconfig /all`) do Set MAC=%%i && GOTO GateIP
    :GateIP
    echo MAC:%MAC%
    arp -s %IP% %MAC%
    echo 正在获取网关信息.....
    FOR /f "skip=17 tokens=13 usebackq " %%i in (`ipconfig /all`) do Set GateIP=%%i && GOTO GateMac
    :GateMac
    echo IP:%GateIP%
    FOR /f "skip=3 tokens=2 usebackq " %%i in (`arp -a %GateIP%`) do Set GateMAC=%%i && GOTO Start
    :Start
    echo MAC:%GateMAC%
    arp -d
    arp -s %GateIP% %GateMAC%
    echo 操作完成!!!
    exit

  • 相关阅读:
    mysql日常~gh-ost使用
    redis基础篇~哨兵
    zeppelin-0.6.0安装配置
    spark 好文链接
    spark API 介绍链接
    solr5.5 基于内置jetty配置 Ubuntu
    Gollum 安装笔记
    手机版测试
    win7 eclipse 调试storm
    (转)Storm UI 解释
  • 原文地址:https://www.cnblogs.com/smwikipedia/p/1424736.html
Copyright © 2011-2022 走看看