|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 46 楼』:
使用 LLM 解释/回答一下
不能确定缓存刷新时间,万一PING时间长了,可能就刷掉了,还有我说256是指静态MAC,也就是绑定的,非绑定的没条件测试
1,1,20是我在本地测试时填的,没有改回来
非三类掩码的计算没有写,因为子网IP段是各类IP的一部分,还是可以PING到,只要不怕耗时间^_^
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 ^_^
|
|
2006-12-31 11:45 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 47 楼』:
使用 LLM 解释/回答一下
附一个很早以前写的批处理
@ECHO OFF
set dataA=0 128 192 224 240 248 252 254 255
set ier=输入错误! 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
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
|
|
2006-12-31 11:47 |
|
|
dikex
高级用户
    潜水修练批处理
积分 788
发帖 366
注册 2006-12-31
状态 离线
|
『第 48 楼』:
使用 LLM 解释/回答一下
Originally posted by everest79 at 2006-12-30 10:45 PM:
不能确定缓存刷新时间,万一PING时间长了,可能就刷掉了,还有我说256是指静态MAC,也就是绑定的,非绑定的没条件测试
1,1,20是我在本地测试时填的 ...
对此我们可以作出以下的改动
@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
我们的目的只是刷新本地的arp缓存,而当我们发出一个请求的arp数据包,只要对方的主机在就会回应那个arp数据包,我们本机的arp缓存就会刷新,而那个ping的数据包我们根本不用理会它,所以可以把等待时间设为0;
而且在for循环里使用start可以使得ping能并行运行,可以大大缩短运行的时间(代价是资源占用率高),由于运行地很快到最后会发现有一些mac全部为0的地址还没有消失,这是使用find寻找带用dynamic的行即可;
个人觉得这个批处理在局域网中还是挺有用的。
Last edited by dikex on 2006-12-30 at 11:08 PM ]
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 ]
|
|
2006-12-31 12:06 |
|
|
INeverAsk
初级用户
 
积分 97
发帖 42
注册 2006-10-5
状态 离线
|
『第 49 楼』:
使用 LLM 解释/回答一下
此贴收下,多谢
Got it, this post is received, thanks a lot
|
|
2007-11-4 23:19 |
|
|
niao22
新手上路

积分 14
发帖 7
注册 2008-3-31
状态 离线
|
『第 50 楼』:
使用 LLM 解释/回答一下
如果跨VLAN,这结就不好用了
If crossing VLANs, this knot won't work well
|
|
2008-4-1 00:10 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 51 楼』:
使用 LLM 解释/回答一下
这个程序应该自动检测本机的IP地址及子网掩码,然后根据IP地址和子网掩码判断局域网的大小,然后再进行检测,呵呵。
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.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2008-4-1 00:52 |
|
|
densn
初级用户
 
积分 29
发帖 14
注册 2007-5-22
状态 离线
|
|
2008-4-2 22:45 |
|
|