|
lovehack2006
初级用户
 
积分 135
发帖 64
注册 2006-12-20
状态 离线
|
『楼 主』:
帮我改进一下这个批处理!!!
使用 LLM 解释/回答一下
各位大哥们,小弟初来,问大哥们点问题!!! (双绑批处理)
下面一个批处理是网吧客户机绑定 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 ]
Dear brothers, I'm a new comer and have some questions to ask you!!! (Double binding batch processing)
The following batch processing is for binding the IP and MAC of the Internet cafe client machine, and it can also bind the MAC and IP of the gateway.
But now there is a problem that this batch processing can only realize the binding of the IP and MAC of the client machine.
If I run arp -d on the client machine to delete the ARP table, or if the ARP table on this machine is empty, this batch can no longer bind the MAC and IP of the gateway of the client machine. ... arp -a %GateIP% >GateMac.txt The content written into gatemac.txt is just -----No ARP Entries Found
Brothers, can you improve this batch processing?
This batch is not written by me, and I can't write this thing. I don't even know how to use for.
I hope you can help me. ...
I have thought of a method by myself: add a ping to the gateway IP in front of this batch, so that the MAC of the gateway can be found in the ARP table. ... or add an arp -s gateway IP gateway MAC at the back, but I wonder if there are other better methods to realize it?
@echo off
::Read the local Mac address
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
::Read the local ip address
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
::Bind the local IP address and MAC address
arp -s %IP% %Mac%
::Read the gateway address
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
::Read the gateway Mac address
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
::Bind the gateway Mac and IP
arp -s %GateIP% %GateMac%
exit
Last edited by lovehack2006 on 2006-12-25 at 01:41 AM ]
|
|
2006-12-23 14:52 |
|
|
lovehack2006
初级用户
 
积分 135
发帖 64
注册 2006-12-20
状态 离线
|
|
2006-12-23 17:39 |
|
|
lovehack2006
初级用户
 
积分 135
发帖 64
注册 2006-12-20
状态 离线
|
|
2006-12-24 04:11 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
@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 去掉即可。不行在跟贴讨论。
@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
It should work. If you want to test it, just remove the echo in front of the last two lines. If it doesn't work, discuss in the reply.
|
|
2006-12-24 09:59 |
|
|
lovehack2006
初级用户
 
积分 135
发帖 64
注册 2006-12-20
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
谢谢楼上的大哥,,不过只是可以绑定本地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 ]
Thanks to the elder brother upstairs,, but only can bind local IP and MAC.
The gateway is not okay.
'getmac /nh /s %local_ip%'
When I run it directly in CMD, it gets like this...
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
Can't get the MAC address of the gateway, don't know why?
When displaying it is like this!
arp -s 10.0.1.1 \Device\NwlnkIpx is wrong here..
The others are all correct, can be fixed correctly!!!1
Last edited by lovehack2006 on 2006-12-25 at 01:40 AM ]
|
|
2006-12-25 14:30 |
|
|
lovehack2006
初级用户
 
积分 135
发帖 64
注册 2006-12-20
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
我的网关IP为10。0。1。1
我现在的测试机子是10。0。0。14
My gateway IP is 10.0.1.1. My current test machine is 10.0.0.14.
|
|
2006-12-25 14:40 |
|
|
lovehack2006
初级用户
 
积分 135
发帖 64
注册 2006-12-20
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
直接在CMD下C:\WINDOWS\system32>getmac
物理地址 传输名称
=================== ==========================================================
00-14-78-37-51-BD \Device\Tcpip_{C9058030-7FD6-4855-8753-443BBFD6A661},
\Device\NwlnkIpx
得到的就是楼上的。。
Directly in CMD, C:\WINDOWS\system32>getmac
Physical Address Transport Name
=================== ==========================================================
00-14-78-37-51-BD \Device\Tcpip_{C9058030-7FD6-4855-8753-443BBFD6A661},
\Device\NwlnkIpx
The one obtained is the above.
|
|
2006-12-25 14:43 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
@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并不是所谓的双绑
双向绑定是指网关绑定本地,本地绑定网关
再者安全的本地绑定应加载于开机脚本才对,动态绑定并不是一个好办法
@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
I also have one for dynamic ARP binding in internet cafes
@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
The owner needs to know that binding two ARPs locally is not what is called double binding
Bidirectional binding means the gateway binds to the local and the local binds to the gateway
Furthermore, a secure local binding should be loaded into the boot script. Dynamic binding is not a good approach
|
|
2006-12-26 01:08 |
|
|
lovehack2006
初级用户
 
积分 135
发帖 64
注册 2006-12-20
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
谢谢楼上的大哥,我做的就是开机执行的脚本的,呵呵!!
谢谢你的批处理,,正在测试中……
Thanks to the elder brother upstairs, what I did is the script executed at startup, heh heh!
Thank you for the batch processing, and I am testing it...
|
|
2006-12-27 07:32 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
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.
Originally posted by lovehack2006 at 2006-12-25 01:30:
Thank you, elder brother upstairs, but it can only bind the local IP and MAC.
It's not possible for the gateway.
'getmac /nh /s %local_ip%'
When I run it directly in CMD, I get this. 㠮..
No way?
I got the correct one. Look at my operation:
c:\>for /f %a in ('getmac /nh /s 192.168.1.77') do @echo %a
00-F0-4C-88-36-20
c:\>
Prove that the correct MAC is obtained.
|
|
2006-12-27 07:40 |
|
|
lovehack2006
初级用户
 
积分 135
发帖 64
注册 2006-12-20
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
我也不知道为什么呀!!
在显示的时候是这样的!
arp -s 10.0.1.1 \Device\NwlnkIpx 就是这里错了。。
其它的都对的,可以正确搞定!!!1
其它的兄弟帮忙一下!
I don't know why either!!
When displaying it's like this!
arp -s 10.0.1.1 \Device\NwlnkIpx is where it's wrong...
The others are all correct and can be done correctly!!!1
Brothers, help out!
|
|
2006-12-28 00:13 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
再试试这个,看行么?
@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
Try this again, see if it works?
@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
|
|
2006-12-28 01:32 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
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
Originally posted by lxmxn at 2006-12-26 06:40 PM:
Can't be?
I got the correct one. Look at my operation:
c:\>for /f %a in ('getmac /nh /s 192.168.1.77') do @echo %a
00-F0-4C-88-36-20
c:\>
His gateway may have disabled ICMP
|
|
2006-12-28 05:39 |
|
|
tao0610
高级用户
    朦胧的世界
积分 579
发帖 218
注册 2006-10-24
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
绑定本机网卡MAC根本没什么实际意义。
真正需要绑定的就是网关MAC,而这个需要手写而不是动态获取。
开机脚本里加入
ARP -S gatewayIP gatewayMAC
Binding the MAC address of the local network card is not really meaningful.
The one that really needs to be bound is the gateway MAC, and this needs to be handwritten instead of dynamically obtained.
Add in the boot script
ARP -S gatewayIP gatewayMAC
|

认识自己,降伏自己,改变自己,才能改变别人! |
|
2006-12-28 06:53 |
|
|
lovehack2006
初级用户
 
积分 135
发帖 64
注册 2006-12-20
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
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
楼上的说的是对的,看来我要用静态的了!!!
Originally posted by lxmxn at 2006-12-27 12:32 PM:
Try this again, see if it works?
@echo off
for /f "delims=: tokens=2" %%a in ('ipconfig /all^|find "Physical Address"') do set local_mac=%%a
f ...
The result I got with yours is like this
arp -s 10.0.0.49 00-14-78-37-51-BC
arp -s 10.0.1.1
What the person upstairs said is correct. It seems I need to use static ones!!!
|
|
2007-1-1 03:20 |
|