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
| Rater | Score | Time |
| redtek |
+10 |
2007-02-02 06:40 |