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-09-24 15:56
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] Find MAC by intranet host IP or host name View 2,340 Replies 9
Original Poster Posted 2007-02-02 00:56 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
20-year member
UID 62249
Status Offline
When bored, I post something to play around. There is a small software called Remote Power On. That small software can not only obtain the MAC address of the corresponding host by entering the IP, but also can remotely power on the host through the MAC.

As for how to use the MAC to remotely power on, I think it is difficult to implement with batch (those who can implement it, post a reply). But how to find the other party's MAC according to the IP or hostname can be implemented through the following code:


@ECHO OFF
REM Query the MAC address of the LAN host by IP or hostname
REM This program is made by Xiaobudian (Qiuyu), QQ: 9399100
:G
CLS
SET /P IP=Please enter the host name or its IP you want to query:
PING %IP% -n 1|FIND /I "could not"
IF "%ERRORLEVEL%"=="0" GOTO :G
FOR /F "TOKENS=2 DELIMS=" %%A IN ('PING %IP% -n 1^|FIND /I "



Floor 2 Posted 2007-02-02 06:01 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
20-year member
UID 62249
Status Offline
Modify the code again to fix the error of not being able to obtain the local MAC, add the function of obtaining the MAC of all or specified IP segments, and also add the functions of MAC-IP binding and unbinding.

In addition, since it is slow to obtain all MACs, I started using the PING command and found it surprisingly slow. Finally, I changed to the TRACERT command and it was twice as fast, but scanning the entire network still takes about 1 minute. If there is a better method, I hope to post a reply


@ECHO OFF
REM MAC Scanning and Binding Tool V1.0
REM Fixed the problem of not being able to check the local MAC (special handling); fixed the problem of not finding the MAC after binding or unbinding (first add ARP -A);
REM Fixed the problem of not being able to obtain the MAC of the router or modem (add other identification symbols when using FIND for precise search or use ARP -A IP);
REM Added IP binding MAC function to prevent ARP spoofing; added IP unbinding MAC function to temporarily eliminate ARP spoofing
REM This program is made by Xiaobudian (Qiuyu), welcome to communicate QQ: 9399100

TITLE MAC Scanning and Binding Tool V1.0
FOR /F "TOKENS=15" %%I IN ('IPCONFIG /ALL^|FIND /I "IP Address"') DO SET LIP=%%I
:G
CLS
ARP -A >NUL
SET IP=
SET MAC=
SET /P IP=Please enter the host name or its IP to be queried (press Enter directly for this computer, enter ALL for all):
IF NOT DEFINED IP GOTO :LIP
IF "%IP%"=="%LIP%" GOTO :LIP
IF "%IP%"=="ALL" GOTO :ALLIP
PING %IP% -n 1 >NUL
REM FOR /F "TOKENS=2" %%I IN ('ARP -A^|FIND "%IP% "') DO SET MAC=%%I
FOR /F "TOKENS=2" %%I IN ('ARP -A %IP% ^|FIND "%IP% "') DO SET MAC=%%I
IF NOT DEFINED MAC GOTO :G
GOTO :IPOK

:LIP
SET IP=%LIP%
FOR /F "TOKENS=12" %%I IN ('IPCONFIG /ALL^|FIND /I "Physical Address"') DO SET MAC=%%I
GOTO :IPOK

:ALLIP
CLS
SET STARTIP=
SET ENDIP=
ECHO Querying the MAC of all hosts will take a long time, you can set a start segment and end segment.
SET /P STARTIP=Please enter the starting segment of the IP to be scanned (minimum is 0, maximum is 254, default is 0):
IF NOT DEFINED STARTIP SET STARTIP=0
SET /P ENDIP=Please enter the ending segment of the IP to be scanned (minimum is 0, maximum is 254, default is 254):
IF NOT DEFINED ENDIP SET ENDIP=254
CLS
FOR /F "TOKENS=1-4 DELIMS=." %%A IN ("%LIP%") DO SET DOMAIN=%%A.%%B.%%C
ECHO Will scan: %DOMAIN%.%STARTIP%-%DOMAIN%.%ENDIP% all hosts' MAC, please wait.....
FOR /L %%I IN (%STARTIP%,1,%ENDIP%) DO TRACERT -h 1 -w 1 %DOMAIN%.%%I >NUL
GOTO :IPOK

:IPOK
CLS
ECHO ------------------------------------------------------
ECHO The MAC of the host %IP% you want to query is: %MAC%
IF "%IP%"=="ALL" (ARP -A|FINDSTR /I "dynamic static")
ECHO ------------------------------------------------------
ECHO.
ECHO.
ECHO Operation completed, please select other operations:
ECHO ******************************************************
ECHO To continue querying MAC, enter G; to exit querying MAC, enter E;
ECHO To bind this IP to this MAC, enter Y; to unbind this, enter N;
ECHO To relatively completely solve the attack of ARP virus, enter Z;
ECHO ******************************************************
SET /P S=Please select and enter the operation to continue:
IF "%S%"=="%S%" GOTO :%S%

:Y
ECHO.
ECHO.
IF "%IP%"=="ALL" (SET /P IP=Please select and enter an IP to be bound from the above list, press Enter directly to bind all:)
IF "%IP%"=="ALL" SET IP=dynamic
FOR /F "TOKENS=1-2" %%I IN ('ARP -A^|FINDSTR /I "%IP%"') DO (ARP -S %%I %%J)
GOTO :G

:N
ECHO.
ECHO.
IF "%IP%"=="ALL" (SET /P IP=Please select and enter the IP to be unbound from the list, press Enter directly to delete all bindings:)
IF "%IP%"=="ALL" SET IP=*
ARP -D %IP%
GOTO :G

:Z
IF EXIST %WINDIR%\SYSTEM32\NPPTOOLS.DLL REN %WINDIR%\SYSTEM32\NPPTOOLS.DLL NPPTOOLS.DL_ >NUL
ARP -D
PING %IP% -n 1 >NUL
FOR /F "TOKENS=12" %%I IN ('IPCONFIG /ALL^|FIND /I "Physical Address"') DO (ARP -S %LIP% %%I)
FOR /F "TOKENS=13" %%I IN ('IPCONFIG /ALL^|FIND /I "Default Gateway"') DO (SET DG=%%I)
PING %DG% -n 1 >NUL
FOR /F "TOKENS=2" %%I IN ('ARP -A^|FIND "%DG% "') DO (ARP -S %DG% %%I)
GOTO :G

:E
@ECHO OFF
EXIT


[ Last edited by HUNRYBECKY on 2007-2-3 at 06:04 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +10 2007-02-02 06:40
Floor 3 Posted 2007-02-02 08:28 ·  中国 广东 广州 番禺区 广州海之光通讯技术有限公司
初级用户
★★
Credits 138
Posts 55
Joined 2007-02-02 05:54
19-year member
UID 78395
Gender Male
Status Offline
Support the person above..

It's best to be like this "

Choice: Output to IP-MAC to TXT?

Hehe. Suggestion!
Floor 4 Posted 2007-02-02 09:35 ·  中国 广西 梧州 电信
初级用户
Credits 22
Posts 11
Joined 2006-05-11 11:29
20-year member
UID 55321
Status Offline
Floor 5 Posted 2007-02-02 12:19 ·  新西兰 奥克兰大区 奥克兰 Microsoft
高级用户
★★
Credits 783
Posts 268
Joined 2006-12-26 17:18
19-year member
UID 74627
Gender Male
Status Offline
菩提本无树,明镜亦非台,本来无一物,何处惹尘埃.
Floor 6 Posted 2007-02-02 14:12 ·  中国 广东 广州 番禺区 电信
初级用户
★★
Credits 197
Posts 77
Joined 2006-09-19 14:02
20-year member
UID 63074
Gender Male
Status Offline
Support... Needs to be studied
Floor 7 Posted 2007-02-02 21:18 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
20-year member
UID 62249
Status Offline
Originally posted by PPdos at 2007-2-2 12:19:
Batch processing for querying Mac manufacturer information


Thank you brother for providing the query, but it seems this is not of much use. In a diskless system, it can still be used to obtain the manufacturer code. Can you tell me what the purpose of this program is? This one seems unable to query the complete MAC address, so it can't be used in my program.
Floor 8 Posted 2007-02-03 02:17 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
20-year member
UID 62249
Status Offline
Originally posted by bosskof at 2007-2-2 09:35:
getmac /s


This command is good for getting the local real physical MAC, but it seems troublesome to get the external MAC, after all, you need to provide the username and password.
Floor 9 Posted 2007-02-03 04:50 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
21-year member
UID 42173
Gender Male
Status Offline
毕竟要提供用户名和密码。

这是因为getmac实际上是通过 WMI 操作的
After all, you need to provide a username and password.

This is because getmac actually operates through WMI

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 10 Posted 2007-02-04 00:42 ·  中国 山西 太原 电信
初级用户
Credits 56
Posts 22
Joined 2006-12-13 10:54
19-year member
UID 73399
Gender Male
Status Offline
Support
Forum Jump: