China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-02 23:44
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Please provide the batch processing content that needs to be improved so that I can help you translate and improve it. View 2,099 Replies 16
Original Poster Posted 2006-12-23 14:52 ·  中国 广东 深圳 电信
初级用户
★★
Credits 135
Posts 64
Joined 2006-12-20 04:35
19-year member
UID 74003
Gender Male
Status Offline
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 ]
Floor 2 Posted 2006-12-23 17:39 ·  中国 广东 深圳 电信
初级用户
★★
Credits 135
Posts 64
Joined 2006-12-20 04:35
19-year member
UID 74003
Gender Male
Status Offline
Floor 3 Posted 2006-12-24 04:11 ·  中国 广东 深圳 电信
初级用户
★★
Credits 135
Posts 64
Joined 2006-12-20 04:35
19-year member
UID 74003
Gender Male
Status Offline
No way, no one replies?
Floor 4 Posted 2006-12-24 09:59 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline


@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.
Floor 5 Posted 2006-12-25 14:30 ·  中国 广东 深圳 电信
初级用户
★★
Credits 135
Posts 64
Joined 2006-12-20 04:35
19-year member
UID 74003
Gender Male
Status Offline
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 ]
Floor 6 Posted 2006-12-25 14:40 ·  中国 广东 深圳 电信
初级用户
★★
Credits 135
Posts 64
Joined 2006-12-20 04:35
19-year member
UID 74003
Gender Male
Status Offline
My gateway IP is 10.0.1.1. My current test machine is 10.0.0.14.
Floor 7 Posted 2006-12-25 14:43 ·  中国 广东 深圳 电信
初级用户
★★
Credits 135
Posts 64
Joined 2006-12-20 04:35
19-year member
UID 74003
Gender Male
Status Offline
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.
Floor 8 Posted 2006-12-26 01:08 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline

@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
Floor 9 Posted 2006-12-27 07:32 ·  中国 广东 深圳 龙岗区 电信
初级用户
★★
Credits 135
Posts 64
Joined 2006-12-20 04:35
19-year member
UID 74003
Gender Male
Status Offline
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...
Floor 10 Posted 2006-12-27 07:40 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
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.
Floor 11 Posted 2006-12-28 00:13 ·  中国 广东 深圳 电信
初级用户
★★
Credits 135
Posts 64
Joined 2006-12-20 04:35
19-year member
UID 74003
Gender Male
Status Offline
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!
Floor 12 Posted 2006-12-28 01:32 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

  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
Floor 13 Posted 2006-12-28 05:39 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
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
Floor 14 Posted 2006-12-28 06:53 ·  中国 北京 朝阳区 联通
高级用户
★★
朦胧的世界
Credits 579
Posts 218
Joined 2006-10-24 04:29
19-year member
UID 67972
Status Offline
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

认识自己,降伏自己,改变自己
,才能改变别人!
Floor 15 Posted 2007-01-01 03:20 ·  中国 广东 深圳 电信
初级用户
★★
Credits 135
Posts 64
Joined 2006-12-20 04:35
19-year member
UID 74003
Gender Male
Status Offline
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!!!
Forum Jump: