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-06-28 01:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Original: 原创!发个实用的局域网快速检测批处理(3月16日更新) Translation: Original! Post a practical LAN quick detection batch processing (updated on March 16) View 3,330 Replies 15
Original Poster Posted 2008-03-09 18:30 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
The original code is as follows. I know there are a lot of things for detecting the local area network now, but I just like to P, and it feels different to use my own things. Hehe (mainly because I can modify and improve it in time):
@echo off&color 9f&setlocal EnableDelayedExpansion
title LAN Quick Detection Tool
echo.
echo.
echo ************************** LAN Quick Detection Tool **************************
echo   *----------------------------------------------------------------------*
echo   * This tool integrates functions of detecting the local machine's network card, detecting the gateway, and finding all online computers in the LAN. In particular, when there are active ARP trojans in the LAN, it can quickly find out the problematic computers. To prevent errors with dual network cards, this tool also adds the function of users entering IPs by themselves. Please create text documents (.txt) named gateway and use in the folder where the tool is located before using this tool. Enter the IP and MAC address of the LAN gateway in gateway in sequence. Note that there should be no space between the IP and MAC. Enter the IP addresses of all computers in the LAN and the departments or people using them in use in sequence. Enter one group per line and note to add a ":" after the IP. This is to determine the end character of the string when finding the IP (this will not find IPs ending with "*#" and "*$#" when finding IPs ending with "#", such as 1 21 181).               *
echo *----------------------------------------------------------------------*
echo   *  Note: Please temporarily close all applications when detecting the LAN. Many black windows will pop up during the detection, which are running the ping test commands. Just wait for one minute, and all the pop-up windows will close by themselves. *
echo   *----------------------------------------------------------------------*
echo   ************************************************************************
pause
cls&mode con lines=15
set u=■■■■■■■■■■■■■■■■■■■■■■■■■
set a=0
for /l %%i in (1,1,20) do call :show %%i
cls
echo.&echo.&echo.&echo.
echo The program is initializing...
echo ┌─────────────────────────┐
echo %u%100%%
echo └─────────────────────────┘
ping /n 3 127.1 >nul
if exist l*.txt del l*.txt
if exist mac*.txt del mac*.txt
if exist jiance.txt del jiance.txt
______________________________________________
rem Ping test for the local machine's network card
cls
echo.&echo.&echo.&echo.
set/p lan= Please enter the LAN segment (the input format is 192.168.1., press Enter directly to default to 192.168.1.):
if "%lan%"=="" goto p1
goto p2
:p1
set lan=192.168.1.
:p2
cls
echo.&echo.&echo.&echo.
set/p ip= Please enter the last digit of the local machine's LAN IP address (press Enter directly to default to 255):
if "%ip%"=="" goto p3
ping %lan%%ip% -n 2 >nul
if errorlevel 2 goto wrong1
if errorlevel 1 goto wrong1
goto show1
:p3
ping %lan%255 -n 2 >nul
if errorlevel 2 goto wrong1
if errorlevel 1 goto wrong1
:show1
cls
echo.&echo.&echo.&echo.
echo   ====================================
echo   ****************************** Network card is unobstructed!*******************************
echo   ====================================
ping -n 3 127.1 >nul
______________________________________________
rem Ping test for the gateway
cls&arp -d 2>nul
echo.&echo.&echo.&echo.
set/p pi= Please enter the last digit of the LAN gateway IP address (press Enter directly to default to 1):
if "%pi%"=="" goto p4
ping %lan%%pi% -n 2 >nul
if errorlevel 2 goto wrong2
if errorlevel 1 goto wrong2
goto select1
:p4
ping %lan%1 -n 2 >nul
if errorlevel 2 goto wrong2
if errorlevel 1 goto wrong2
goto select1
______________________________________________
rem Ping test for the LAN to find all online computers
:ping
echo. >lb.txt
echo. >>lb.txt
echo   ==================================== >>lb.txt
echo   ************************ The following computers in the LAN are online! ************************ >>lb.txt
echo   ==================================== >>lb.txt
for /l %%i in (0,1,255) do start ping -n 1 %lan%%%i
for /f "skip=3 tokens=*" %%k in ('arp -a') do echo %%k >>mac.txt
for /f "tokens=1" %%j in ('findstr /c:"dynamic" mac.txt') do (
findstr /c:"%%j:" use.txt >>lb.txt
)
cls&mode con lines=30&type lb.txt | more
pause
______________________________________________
rem Detect if there is ARP spoofing in the LAN
cls&fc gateway.txt jiance.txt
if errorlevel 2 goto find
if errorlevel 1 goto find
goto show2
______________________________________________
rem Find the computers infected with the trojan
:find
cls
echo. >ld.txt
echo. >>ld.txt
echo   ==================================== >>ld.txt
echo   ********************* The above computers in the LAN are infected with ARP trojans!********************* >>ld.txt
echo   ==================================== >>ld.txt

for /f "skip=3 tokens=2" %%i in (la.txt) do findstr /c:"%%i" mac.txt >>lc.txt
for /f "tokens=1" %%i in (lc.txt) do findstr /c:"%%i:" use.txt >>ld.txt
type ld.txt | more
pause
______________________________________________
:end
cls&mode con lines=15
echo.&echo.&echo.&echo.
echo   ====================================
echo ************************* Detection completed, press any key to exit!**************************
echo ====================================
pause >nul
del l*.txt jiance.txt mac*.txt&goto :eof
:show2
cls&mode con lines=15
echo.&echo.&echo.&echo.
echo   ====================================
echo   ***************** After detection, there is no ARP spoofing in the LAN, and the network is secure! ******************
echo   ====================================
pause
goto end
:select1
cls
echo.&echo.&echo.&echo.
echo   ====================================
echo   ***************************** Gateway is unobstructed!********************************
echo   ====================================
ping -n 2 127.1 >nul&arp -a >la.txt
cls&for /f "skip=3 tokens=1,2" %%i in ('arp -a') do echo %%i%%j >>jiance.txt
:select2
cls
echo.&echo.&echo.&echo.
set/p select2= Do you want to ping test the LAN? (1. Ping test 2. Do not ping test)
if "%select2%"=="1" goto ping
if "%select2%"=="2" goto end
cls
echo.&echo.&echo.&echo.
echo   ====================================
echo   ***************************** Incorrect input!********************************
echo   ====================================
ping -n 2 127.1 >nul&goto select2
:wrong1
cls
echo.&echo.&echo.&echo.
echo   ====================================
echo   ************************** Network card is not unobstructed, unable to detect!*************************
echo   ====================================
ping -n 3 127.1 >nul&goto :eof
:wrong2
cls
echo.&echo.&echo.&echo.
echo   ====================================
echo   ************************** Network is not unobstructed, unable to detect!*************************
echo   ====================================
ping -n 3 127.1 >nul&goto :eof
:show
cls
set /a a+=4
echo.&echo.&echo.&echo.
echo The program is initializing...
echo ┌─────────────────────────┐
echo !u:~,%1!%a%%%&ping /n 1 127.1 >nul
echo └─────────────────────────┘
goto :eof


[ Last edited by zw19750516 on 2008-3-16 at 02:57 PM ]
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
bjsh +4 2008-03-10 18:46
vlq2599 +1 2008-03-26 17:23
Floor 2 Posted 2008-03-10 00:52 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Hehe, no one cares, I'll cheer myself up.
Floor 3 Posted 2008-03-10 12:53 ·  中国 广东 深圳 联通
初级用户
Credits 89
Posts 36
Joined 2007-12-20 15:37
18-year member
UID 106247
Gender Male
Status Offline
Thanks for sharing.
Learned...
Floor 4 Posted 2008-03-10 13:38 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Skills for handling special characters in the set command, the LZ used it well, heh.
Floor 5 Posted 2008-03-10 18:46 ·  中国 浙江 杭州 电信
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
Floor 6 Posted 2008-03-10 18:49 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Thanks, boss. Let's all work hard together!
Floor 7 Posted 2008-03-10 21:03 ·  中国 浙江 杭州 阿里云
初级用户
Credits 20
Posts 8
Joined 2007-07-04 09:36
18-year member
UID 93087
Gender Male
Status Offline
Oh, so many windows. I almost got scared by it, heh!
Floor 8 Posted 2008-03-11 03:21 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Everyone, please pay attention to closing other applications during the detection. The characteristic of this P is fast, but it also causes a shortcoming: occupying extremely high memory within a short time (about one minute). It is recommended that those with poor computer configurations do not use it.
Floor 9 Posted 2008-03-11 09:56 ·  中国 上海 普陀区 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
Floor 10 Posted 2008-03-11 19:38 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
I have also checked for incorrect codes, detected various situations, and made aesthetic improvements. Everyone can rest assured to test and use it.
Floor 11 Posted 2008-03-16 13:46 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
In order to improve together for everyone, I have to be a bit selfish and bump it myself, hehe.
Floor 12 Posted 2008-03-17 10:40 ·  中国 黑龙江 大庆 大庆中基石油通信建设有限公司
新手上路
Credits 8
Posts 4
Joined 2008-01-08 16:14
18-year member
UID 107999
Gender Male
Status Offline
Thanks for sharing. Learned...
Floor 13 Posted 2008-03-26 13:31 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
```batch
@echo off&color 9f&setlocal EnableDelayedExpansion
title LAN Quick Detection Tool
echo.
echo.
echo ************************** LAN Quick Detection Tool **************************
echo   *----------------------------------------------------------------------*
echo   * This tool integrates functions of detecting the local area network card, detecting the gateway, and finding all online computers in the LAN. In particular, when there are active ARP trojans in the LAN, it can quickly find out the problematic computers. To prevent errors with dual network cards, this tool also adds the function of user inputting IP. Before using this tool, please create text documents (.txt) named gateway and use in the folder where the tool is located. In gateway, input the IP and MAC address of the LAN gateway in sequence. Note that there should be no space between IP and MAC. In use, input the IP addresses of all computers in the LAN and the department or person in use in sequence. Input one group per line and note that add a ":" after the IP. This is to determine the end character of the string when finding the IP (so that the IP ending with "#" will not be found when finding the IP ending with "*#" and "*#*", such as 1 21 181).   *
echo *----------------------------------------------------------------------*
echo   *  Note: Please temporarily close all applications when detecting the LAN. Many black windows will pop up during the detection, which is running the ping test command. Just wait for one minute, and all pop-up windows will close automatically. *
echo   *----------------------------------------------------------------------*
echo   ************************************************************************
pause
cls&mode con lines=15
set u=■■■■■■■■■■■■■■■■■■■■■■■■■
set a=0
for /l %%i in (1,1,20) do call :show %%i
cls
echo.&echo.&echo.&echo.
echo Program is initializing...
echo ┌─────────────────────────┐
echo %u%100%%
echo └─────────────────────────┘
ping /n 3 127.1 >nul
if exist l*.txt del l*.txt
if exist mac*.txt del mac*.txt
if exist jiance.txt del jiance.txt
______________________________________________
rem Ping test for the local area network card
cls
set lan=192.168.1.
echo.&echo.&echo.&echo.
set/p lan= Please enter the LAN segment (input format is 192.168.1., press Enter directly to default to 192.168.1.):
cls
set ip=255
echo.&echo.&echo.&echo.
set/p ip= Please enter the last digit of the local LAN IP address (press Enter directly to default to 255):
ping %lan%%ip% -n 2 >nul
if errorlevel 1 goto wrong1
cls
echo.&echo.&echo.&echo.
echo   ====================================
echo   ****************************** Network card is unobstructed!*******************************
echo   ====================================
ping -n 3 127.1 >nul
______________________________________________
rem Ping test for the gateway
cls&arp -d 2>nul
set pi=1
echo.&echo.&echo.&echo.
set/p pi= Please enter the last digit of the LAN gateway IP address (press Enter directly to default to 1):
ping %lan%%pi% -n 2 >nul
if errorlevel 1 goto wrong2
goto select1
______________________________________________
rem Ping test for the LAN to find all online computers
:ping
echo. >lb.txt
echo. >>lb.txt
echo   ==================================== >>lb.txt
echo   ************************ The following computers in the LAN are online! ************************ >>lb.txt
echo   ==================================== >>lb.txt
for /l %%i in (0,1,255) do start ping -n 1 %lan%%%i
for /f "skip=3 tokens=*" %%k in ('arp -a') do echo %%k >>mac.txt
for /f "tokens=1" %%j in ('findstr /c:"dynamic" mac.txt') do (
findstr /c:"%%j:" use.txt >>lb.txt
)
cls&mode con lines=30&type lb.txt | more
pause
______________________________________________
rem Detect whether there is ARP spoofing in the LAN
cls&fc gateway.txt jiance.txt
if errorlevel 2 goto find
if errorlevel 1 goto find
goto show2
______________________________________________
rem Find the computer infected with the trojan
:find
cls
echo. >ld.txt
echo. >>ld.txt
echo   ==================================== >>ld.txt
echo   ********************* The above computers in the LAN are infected with ARP trojans!********************* >>ld.txt
echo   ==================================== >>ld.txt

for /f "skip=3 tokens=2" %%i in (la.txt) do findstr /c:"%%i" mac.txt >>lc.txt
for /f "tokens=1" %%i in (lc.txt) do findstr /c:"%%i:" use.txt >>ld.txt
type ld.txt | more
pause
______________________________________________
:end
cls&mode con lines=15
echo.&echo.&echo.&echo.
echo   ====================================
echo ************************* Detection completed, press any key to exit!**************************
echo ====================================
pause >nul
del l*.txt jiance.txt mac*.txt&goto :eof
:show2
cls&mode con lines=15
echo.&echo.&echo.&echo.
echo   ====================================
echo   ***************** After detection, there is no ARP spoofing in the LAN, and the network is secure! ******************
echo   ====================================
pause
goto end
:select1
cls
echo.&echo.&echo.&echo.
echo   ====================================
echo   ***************************** Gateway is unobstructed!********************************
echo   ====================================
ping -n 2 127.1 >nul&arp -a >la.txt
cls&for /f "skip=3 tokens=1,2" %%i in ('arp -a') do echo %%i%%j >>jiance.txt
:select2
cls
echo.&echo.&echo.&echo.
set/p select2= Do you want to ping test the LAN? (1. Ping test 2. Do not ping test)
if "%select2%"=="1" goto ping
if "%select2%"=="2" goto end
cls
echo.&echo.&echo.&echo.
echo   ====================================
echo   ***************************** Incorrect input!********************************
echo   ====================================
ping -n 2 127.1 >nul&goto select2
:wrong1
cls
echo.&echo.&echo.&echo.
echo   ====================================
echo   ************************** Network card is not connected, unable to detect!*************************
echo   ====================================
ping -n 3 127.1 >nul&goto :eof
:wrong2
cls
echo.&echo.&echo.&echo.
echo   ====================================
echo   ************************** Network is not connected, unable to detect!*************************
echo   ====================================
ping -n 3 127.1 >nul&goto :eof
:show
cls
set /a a+=4
echo.&echo.&echo.&echo.
echo Program is initializing...
echo ┌─────────────────────────┐
echo !u:~,%1!%a%%%&ping /n 1 127.1 >nul
echo └─────────────────────────┘
goto :eof
```
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
vlq2599 +1 2008-03-26 17:23
p1509101 +2 2008-04-05 14:18
Floor 14 Posted 2008-03-26 16:44 ·  中国 江苏 南京 电信
初级用户
Credits 36
Posts 17
Joined 2008-01-07 13:19
18-year member
UID 107895
Gender Male
Status Offline
Great, learning from you~
Floor 15 Posted 2008-03-26 17:24 ·  中国 河南 安阳 联通
新手上路
Credits 7
Posts 10
Joined 2006-01-09 16:15
20-year member
UID 48691
Gender Male
Status Offline
Bro, not bad. I can only give you one point. Don't mind it being little.
Forum Jump: