• 资讯 国内 | 国际 | 政策 | 财经 | 展会 | 评论 | 人物 产品  服务器 | 防火墙 | 网络设备 | 存储 | 芯片
  • 安全 攻击 | 防御 | 市场 | 新闻  互联网  创业 | 融资 | 域名 | 网游 | 搜索 | 电子商务 | SEO | IM
  • 专题 IBM | DELL | 网通 | 电信 | 微软 | Google | 阿里巴巴 | 百度 知识库 新技术 | 术语 | 数据恢复






  • IDC天下 >> 安全 >> 攻击>> ARP静态绑定批处理文件脚本详细讲解

    ARP静态绑定批处理文件脚本详细讲解

    来源:51cto.com 发布时间:2007年10月11日 作者:emily 阅读次数:
    TAG: 暂无标签

    网上流传了很多对付ARP欺骗的批处理脚本,本文是对比较流行的一个脚本加以注释和讲解,希望对广大51CTO网友和网管员有用。原批处理文件如下:

    @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

    【相关文章】

    • 专题:ARP攻击防范与解决方案
    • ARP欺骗攻击原理也可以这样理解
    0

  • 无相关内容