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-24 07:46
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » So many experts, who can write a program to scan the internal network IP and mac! View 7,347 Replies 51
Floor 46 Posted 2006-12-31 11:45 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
I can't determine the cache refresh time. If the PING time is long, it might be flushed. Also, when I said 256, it refers to the static MAC, that is, the bound one. There's no condition to test the unbound one.
1,1,20 is what I filled in during local testing and hasn't been changed back.
The calculation of non - class C masks isn't written because the subnet IP segment is part of various types of IPs, and it's still possible to PING, as long as you don't mind taking time ^_^
Floor 47 Posted 2006-12-31 11:47 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Attach an old batch script I wrote earlier

@ECHO OFF
set dataA=0 128 192 224 240 248 252 254 255
set ier=Input error! key:
set con=999
if not "%1" == "" (set con=1&&set go=des) else goto int
if not "%1" == "" echo %1|find ".">nul&&set go=int
goto %go%


:int
cls
if %con% equ 1 (set mask=%1&&set con=0) else set /p mask=MASK:
:chk1
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "tokens=1-4 delims=." %%a in ("%mask%") do if %%a lss 128 (cls&echo %mask% %ier%1 %%a^>128&goto int) else set m_1=%%a&set m_2=%%b&set m_3=%%c&set m_4=%%d
for /f "tokens=2,3 delims==_" %%i in ('set m_') do echo %%j|findstr /v /b /e "%dataA%"&&cls&&echo %mask% %ier%2&&echo 第%%i段 %%j&&goto int
set /a _tmp1=%m_1%+%m_2%+%m_3%+%m_4%
set /a _tmp2=4
:chk2
set /a _tmp3=!m_%_tmp2%!
if not "%_tmp3%" == "0" (echo.) else set /a _tmp2=%_tmp2%-1&&goto chk2
set /a _tmp4=%_tmp1%-%_tmp3%
set /a _tmp5=%dataA:~-3%*(%_tmp2%-1)
if %_tmp4% == %_tmp5% (goto next) else echo %mask% %ier%3&goto int

:next
set /a des1=%_tmp2%*8-8
if "%_tmp3%" == "%dataA:~2,3%" set des2=1
if "%_tmp3%" == "%dataA:~6,3%" set des2=2
if "%_tmp3%" == "%dataA:~10,3%" set des2=3
if "%_tmp3%" == "%dataA:~14,3%" set des2=4
if "%_tmp3%" == "%dataA:~18,3%" set des2=5
if "%_tmp3%" == "%dataA:~22,3%" set des2=6
if "%_tmp3%" == "%dataA:~26,3%" set des2=7
if "%_tmp3%" == "%dataA:~30,3%" set des2=8
set /a des=%des1%+%des2%
echo MASK:%mask%=%des%
ENDLOCAL
goto end

:des
cls
if "%1" == "mask" set con=0
if %con% equ 1 (set mask=%1&&set con=0) else set /p mask=MASK:

:ce
echo %mask%|find "- ."&&cls&&echo %mask% %ier%1&&goto des
set /a mask1=%mask%/8
set /a mask2=%mask%%%8
set /a chk=%mask1%+%mask2%
if %chk% gtr 0 (if %chk% gtr 4 (cls&&echo %mask% %ier%2&&goto des)) else cls&&echo %mask% %ier%3&&goto des
set s1=0&set s2=0&set s3=0&set s4=0&set s5=%mask1%
if "%mask1%" == "0" (set s0=%mask%&&goto ct) else set s0=%mask2%

:cf
set s%s5%=255
set /a s5=%s5%-1
if not "%s5%" == "0" goto cf

:ct
if "%s0%" == "0" set s=%dataA:~0,1%
if "%s0%" == "1" set s=%dataA:~2,3%
if "%s0%" == "2" set s=%dataA:~6,3%
if "%s0%" == "3" set s=%dataA:~10,3%
if "%s0%" == "4" set s=%dataA:~14,3%
if "%s0%" == "5" set s=%dataA:~18,3%
if "%s0%" == "6" set s=%dataA:~22,3%
if "%s0%" == "7" set s=%dataA:~26,3%
if "%s0%" == "8" set s=%dataA:~30,3%
set /a _tmp=%mask1%+1
set s%_tmp%=%s%
echo %mask%=%s1%.%s2%.%s3%.%s4%

:end
pause>nul
exit




Floor 48 Posted 2006-12-31 12:06 ·  中国 广东 广州 天河区 电信
高级用户
★★★
潜水修练批处理
Credits 788
Posts 366
Joined 2006-12-31 02:43
19-year member
UID 75048
Gender Male
Status Offline
Originally posted by everest79 at 2006-12-30 10:45 PM:
Unable to determine the cache refresh time. If the PING time is long, it may be flushed. Also, when I said 256, it refers to the static MAC, that is, the bound one. There are no conditions to test the unbound one.
1,1,20 is what I filled in during local testing...


We can make the following changes:

@echo off
arp /d
FOR /L %%i IN (1,1,255) Do start /b ping 192.168.1.%%i -n 1 -w 0 >nul
arp /a | find "dynamic">IP.txt
type ip.txt
pause


Our purpose is just to refresh the local arp cache. As long as the target host is online, it will respond to the arp packet we send, and our local arp cache will be refreshed. We don't need to care about the ping packet at all, so we can set the wait time to 0.
Moreover, using start in the for loop can make ping run in parallel, which can greatly shorten the running time (with the cost of high resource usage). Since it runs very quickly, in the end, some addresses with all MACs being 0 may not have disappeared yet. At this time, using find to find the lines with "dynamic" can solve the problem.
Personally, I think this batch processing is still quite useful in the local area network.

[ Last edited by dikex on 2006-12-30 at 11:08 PM ]
Floor 49 Posted 2007-11-04 23:19 ·  中国 浙江 温州 平阳县 电信
初级用户
Credits 97
Posts 42
Joined 2006-10-05 22:12
19-year member
UID 64633
Gender Male
Status Offline
Got it, this post is received, thanks a lot
Floor 50 Posted 2008-04-01 00:10 ·  中国 辽宁 葫芦岛 联通
新手上路
Credits 14
Posts 7
Joined 2008-03-31 21:49
18-year member
UID 114595
Gender Male
Status Offline
If crossing VLANs, this knot won't work well
Floor 51 Posted 2008-04-01 00:52 ·  中国 河北 保定 移动
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
This program should automatically detect the local IP address and subnet mask, then determine the size of the local area network based on the IP address and subnet mask, and then conduct the detection, heh heh.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 52 Posted 2008-04-02 22:45 ·  中国 广东 广州 海珠区 电信
初级用户
Credits 29
Posts 14
Joined 2007-05-22 04:46
19-year member
UID 88948
Gender Male
Status Offline
Forum Jump: