标题: 帮我改进一下这个批处理!!!
[打印本页]
作者: lovehack2006
时间: 2006-12-23 14:52
标题: 帮我改进一下这个批处理!!!
各位大哥们,小弟初来,问大哥们点问题!!! (双绑批处理)
下面一个批处理是网吧客户机绑定 IP和MAC的,,也可以绑定网关的MAC和IP
但是现在有一个问题就是这个批处理只能实现客户机的IP与MAC绑定。
如果我在客户机上运行过arp -d 删了ARP表的话,或者如果
这个机子上ARP表是空的话。这个批就不能再绑定
客户机的网关的MAC与IP了。。。arp -a %GateIP% >GateMac.txt
写入到gatemac.txt里的就只是这个了-----No ARP Entries Found
兄弟们能改进一下这个批处理吗?
这个批不是我写的,我也不会写这个东西。。我连for都还不会用。。
希望和位能帮我一下。。。
我自己想过方法的: 在这个批前面加一个ping 网关IP 这样在
ARP表中就可以找到网关的MAC了。。。。。或者在后面加一个
arp -s 网关IP 网关MAC也可以,但是我想有没有其它更好的方法实现?
@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
::读取网关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%
exit
Last edited by lovehack2006 on 2006-12-25 at 01:41 AM ]
作者: lovehack2006
时间: 2006-12-23 17:39
顶起来!!!
作者: lovehack2006
时间: 2006-12-24 04:11
不是吧,没有人回?
作者: lxmxn
时间: 2006-12-24 09:59
@echo off
for /f "delims=: tokens=2" %%a in ('ipconfig /all^|find "Physical Address"') do set local_mac=%%a
for /f "delims=: tokens=2" %%a in ('ipconfig /all^|find "IP Address"') do set local_ip=%%a
for /f "delims=: tokens=2" %%a in ('ipconfig /all^|find "Default Gateway"') do set gate_ip=%%a
for /f %%a in ('getmac /nh /s %local_ip%') do set gate_mac=%%a
echo arp -s %local_ip% %local_mac%
echo arp -s %gate_ip% %gate_mac%
pause
应该可以,测试行的话,把最后两句前面的echo 去掉即可。不行在跟贴讨论。
作者: lovehack2006
时间: 2006-12-25 14:30
谢谢楼上的大哥,,不过只是可以绑定本地IP和MAC
网关的话就不行了。
'getmac /nh /s %local_ip%'
我直接在CMD中运行的话,可以得到的是这样的。。。
C:\WINDOWS\system32>getmac /nh /s 10.0.0.14
00-14-78-37-51-BD \Device\Tcpip_{C9058030-7FD6-4855-8753-443BBFD6A661},
\Device\NwlnkIpx
得不到网关的 mac地址,不知道是为什么?
在显示的时候是这样的!
arp -s 10.0.1.1 \Device\NwlnkIpx 就是这里错了。。
其它的都对的,可以正确搞定!!!1
Last edited by lovehack2006 on 2006-12-25 at 01:40 AM ]
作者: lovehack2006
时间: 2006-12-25 14:40
我的网关IP为10。0。1。1
我现在的测试机子是10。0。0。14
作者: lovehack2006
时间: 2006-12-25 14:43
直接在CMD下C:\WINDOWS\system32>getmac
物理地址 传输名称
=================== ==========================================================
00-14-78-37-51-BD \Device\Tcpip_{C9058030-7FD6-4855-8753-443BBFD6A661},
\Device\NwlnkIpx
得到的就是楼上的。。
作者: everest79
时间: 2006-12-26 01:08
@echo off
for /f "delims=: tokens=2" %%a in ('ipconfig /all^|find "Physical Address"') do set local_mac=%%a
for /f "delims=: tokens=2" %%a in ('ipconfig /all^|find "IP Address"') do set local_ip=%%a
for /f "delims=: tokens=2" %%a in ('ipconfig /all^|find "Default Gateway"') do set gate_ip=%%a
for /f %%a in ('getmac /nh /s %local_ip%') do set gate_mac=%%a
echo arp -s %local_ip% %local_mac%
echo arp -s %gate_ip% %gate_mac%
pause
我这有一个也是写给网吧动态绑定ARP的
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "tokens=2 delims==" %%i in ('nbtstat -a %COMPUTERNAME%') do call set local=!local!%%i
for /f "tokens=3" %%i in ('netstat -r^|find " 0.0.0.0"') do set gm=%%i
for /f "tokens=1,2" %%i in ('arp -a %gm%^|find /i /v "inter"') do set gate=%%i %%j
echo arp -s %gate%
echo arp -s %local%
pause
楼主需要知道你在本地绑定两个ARP并不是所谓的双绑
双向绑定是指网关绑定本地,本地绑定网关
再者安全的本地绑定应加载于开机脚本才对,动态绑定并不是一个好办法
作者: lovehack2006
时间: 2006-12-27 07:32
谢谢楼上的大哥,我做的就是开机执行的脚本的,呵呵!!
谢谢你的批处理,,正在测试中……
作者: lxmxn
时间: 2006-12-27 07:40
Originally posted by lovehack2006 at 2006-12-25 01:30:
谢谢楼上的大哥,,不过只是可以绑定本地IP和MAC
网关的话就不行了。
'getmac /nh /s %local_ip%'
我直接在CMD中运行的话,可以得到的是这样的。。㠮..
不会吧?
我得到了正确的啊。看我操作:
c:\>for /f %a in ('getmac /nh /s 192.168.1.77') do @echo %a
00-F0-4C-88-36-20
c:\>
证明得到的是正确的MAC.
作者: lovehack2006
时间: 2006-12-28 00:13
我也不知道为什么呀!!
在显示的时候是这样的!
arp -s 10.0.1.1 \Device\NwlnkIpx 就是这里错了。。
其它的都对的,可以正确搞定!!!1
其它的兄弟帮忙一下!
作者: lxmxn
时间: 2006-12-28 01:32
再试试这个,看行么?
@echo off
for /f "delims=: tokens=2" %%a in ('ipconfig /all^|find "Physical Address"') do set local_mac=%%a
for /f "delims=: tokens=2" %%a in ('ipconfig /all^|find "IP Address"') do set local_ip=%%a
for /f "delims=: tokens=2" %%a in ('ipconfig /all^|find "Default Gateway"') do set gate_ip=%%a
rem for /f %%a in ('getmac /nh /s %local_ip%') do set gate_mac=%%a
for /f "tokens=2 delims==" %%a in ('nbtstat -A %gate_ip%^|find "MAC Address"') do set gate_mac= %%a
echo arp -s %local_ip% %local_mac%
echo arp -s %gate_ip% %gate_mac%
pause
作者: everest79
时间: 2006-12-28 05:39
Originally posted by lxmxn at 2006-12-26 06:40 PM:
不会吧?
我得到了正确的啊。看我操作:
c:\>for /f %a in ('getmac /nh /s 192.168.1.77') do @echo %a
00-F0-4C-88-36-20
c:\>
他的网关可能禁用了icmp
作者: tao0610
时间: 2006-12-28 06:53
绑定本机网卡MAC根本没什么实际意义。
真正需要绑定的就是网关MAC,而这个需要手写而不是动态获取。
开机脚本里加入
ARP -S gatewayIP gatewayMAC
作者: lovehack2006
时间: 2007-1-1 03:20
Originally posted by lxmxn at 2006-12-27 12:32 PM:
再试试这个,看行么?
@echo off
for /f "delims=: tokens=2" %%a in ('ipconfig /all^|find "Physical Address"') do set local_mac=%%a
f ...
用你这个得到结果是这样
arp -s 10.0.0.49 00-14-78-37-51-BC
arp -s 10.0.1.1
楼上的说的是对的,看来我要用静态的了!!!
作者: flamey
时间: 2007-1-1 05:30
在网上找到的,是谁编写忘了,因为用的时间比较长了!
@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
:::::::::读取网关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%
exit
作者: lovehack2006
时间: 2007-1-3 00:39
楼上的哥们,我说的就是这个批处理的,这个有问题。。。。