中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-16 15:25
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » IP區段掃瞄 目前適用ClassC 查看 916 回复 8
楼 主 IP區段掃瞄 目前適用ClassC 发表于 2007-02-21 14:22 ·  中国 台湾 索尼So-Net娱乐通讯
初级用户
积分 52
发帖 21
注册 2006-01-04 20:41
UID 48443
状态 离线
DEAE SIR:
以下代碼請版上大哥指正,
小弟利用PING指令寫出批次檔,
但由於實力不足,只能做出CLASS C
懇請諸兄幫忙完成A及B。

以下為代碼________________________________________________________________________________________________________________________________________
@echo off
:proceed_start
cls
echo 請輸入查詢IP開始位置(例:10.0.0.1)
set /p ip_start=
if not defined ip_start goto proceed_start
:proceed_end
echo 請輸入查詢IP結束位置(例:10.0.0.255)
set /p ip_end=
if not defined ip_end goto proceed_end
echo.
echo 掃瞄 IP Address 請稍後......
echo.
::以下為副程式呼叫
::===========================================================================
::開始掃瞄初始區段規則
call :check_ip_rules
::===========================================================================
::判斷ip規則等級
call :ip_rulse_scans
::===========================================================================

::依啟動旗標執行功能
::當旗標ip_rules=1
if /i "%ip_rules%"=="0" goto :eof
if /i "%ip_rules%"=="1" for /f "tokens=2 delims=:" %%a in ('ping -n 1 -w 1 %ip_on1%.%ip_on2%.%ip_on3%.%ip_on4%^|find "TTL"') do (
if /i TTL GEQ 0 (echo 設備 Reply form %ip_on1%.%ip_on2%.%ip_on3%.%ip_on4% 與本機電腦連線中)else echo echo 設備 Reply form %ip_on1%.%ip_on2%.%ip_on3%.%ip_on4% 與本機電腦已離線)
::當旗標ip_rules=2

::當旗標ip_rules=3

::當旗標ip_rules=4

::當旗標ip_rules=5

::當旗標ip_rules=6

::當旗標ip_rules=7
if /i "%ip_rules%"=="7" for /l %%a in (%ip_on4% 1 %ip_on5%) do (
for /f "tokens=1 delims=:" %%a in ('ping -n 1 -w 1 %ip_on1%.%ip_on2%.%ip_on3%.%%a^|findstr "TTL"') do (
if /i TTL GEQ 0 (echo 設備 %%a 與本機電腦連線中)else echo 設備 %%a 與本機電腦已離線))

::if /i "%ip_rules%"=="7" for /l %%a in (%ip_on4% 1 %ip_on5%) do (
:: for /f "tokens=1 delims=:" %%a in ('ping -n 1 -w 1 %ip_on1%.%ip_on2%.%ip_on3%.%%a^|findstr "TTL"') do (
:: if /i TTL GEQ 0 (echo %ip_on1%.%ip_on2%.%ip_on3%.%%a 連線中)else echo %ip_on1%.%ip_on2%.%ip_on3%.%%a 已離線))

::當旗標ip_rules=8
::if /i "%ip_rules%"=="8" for /f "tokens=1 delims=:" %%a in ('ping -n 1 -w 1 %ip_on1%.%ip_on2%.%ip_on3%.%ip_on4%^|find "TTL"') do
::if /i TTL gtr 0 (echo %ip_on1%.%ip_on2%.%ip_on3%.%ip_on4% 連線中) else echo %ip_on1%.%ip_on2%.%ip_on3%.%ip_on4% 已離線

::for /l %%a in (%start_no4% 1 %end_no4%) do (
::ping -w 1 -n 1 %start_no1%.%start_no2%.%start_no3%.%%a)
::pause>unl
pause>unl
exit
::===========================================================================
::副程式:check_ip_rules開始
:check_ip_rules
::開始掃瞄初始區段規則
for /f "tokens=1-4 delims=." %%a in ("%ip_start%") do (
set start_no1=%%a
set start_no2=%%b
set start_no3=%%c
set start_no4=%%d
)
::判斷輸入規則是否大於255,若大於255則進位
if /i %start_no1% gtr 255 set /a start_no2=start_no2+1
if /i %start_no2% gtr 255 set /a start_no3=start_no3+1
if /i %start_no3% gtr 255 set /a start_no4=start_no4+1
if /i %start_no1% gtr 255 set /a start_no1=255
if /i %start_no2% gtr 255 set /a start_no2=255
if /i %start_no3% gtr 255 set /a start_no3=255
::判斷輸入末端規則是否大於255,若大於255則結束程序
if /i %start_no4% gtr 255 goto :error1
::判斷末端規則是否小於等於0,若小於0則結束程序
if /i %start_no4% leq 0 goto :error1
::開始掃瞄結束區段規則
for /f "tokens=1-4 delims=." %%a in ("%ip_end%") do (
set end_no1=%%a
set end_no2=%%b
set end_no3=%%c
set end_no4=%%d
)
::判斷輸入規則是否大於255,若大於255則進位
if /i %end_no1% gtr 255 set /a end_no2=end_no2+1
if /i %end_no2% gtr 255 set /a end_no3=end_no3+1
if /i %end_no3% gtr 255 set /a end_no4=end_no4+1
if /i %end_no1% gtr 255 set /a end_no1=255
if /i %end_no2% gtr 255 set /a end_no2=255
if /i %end_no3% gtr 255 set /a end_no3=255
::判斷輸入末端規則是否大於255,若大於255則結束程序
if /i %end_no4% gtr 255 goto :error1
::判斷末端規則是否小於等於0,若小於0則結束程序
if /i %end_no4% leq 0 goto :error1
::判斷開始區段位置大於結束區段位置
if /i %start_no1% gtr %start_no1% goto error2
::字元補償-加速用

goto :eof
::副程式:check_ip_rules結束
::===========================================================================

::判斷ip規則等級
::兩者ip相同
:ip_rulse_scans
:condition1-1
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% set ip_on1=%start_no1%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% set ip_on2=%start_no2%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% set ip_on3=%start_no3%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% set ip_on4=%start_no4%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% echo 符合condition1-1
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% set /a ip_rules=1

:condition2-1
::classA-1
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% set ip_on1=%start_no1%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% set ip_on2=%start_no2%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% set ip_on3=%start_no3%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% set ip_on4=%start_no4%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% set ip_on5=%end_no2%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% echo 符合condition2-1
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% set /a ip_rules=2
if /i %start_no1%==%end_no1% if /i %start_no2% gtr %end_no2% if /i %start_no3%==%end_no3% if /i %start_no4%==%end_no4% set /a ip_rules=0 & goto error2
:condition2-2
::classA-2
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% set ip_on1=%start_no1%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% set ip_on2=%start_no2%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% set ip_on3=%start_no3%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% set ip_on4=%start_no4%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% set ip_on5=%end_no2%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% set ip_on6=%end_no3%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% echo 符合condition2-2
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% set /a ip_rules=3

:condition2-3
::classA-3
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set ip_on1=%start_no1%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set ip_on2=%start_no2%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set ip_on3=%start_no3%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set ip_on4=%start_no4%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set ip_on5=%end_no2%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set ip_on6=%end_no3%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set ip_on7=%end_no4%
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% echo 符合condition2-3
if /i %start_no1%==%end_no1% if /i %start_no2% lss %end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set /a ip_rules=4

:condition3-1
::classB-1
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% set ip_on1=%start_no1%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% set ip_on2=%start_no2%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% set ip_on3=%start_no3%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% set ip_on4=%start_no4%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% set ip_on5=%end_no3%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% echo 符合condition3-1
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4%==%end_no4% set /a ip_rules=5
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% gtr %end_no4% set /a ip_rules=5
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% gtr %end_no3% if /i %start_no4%==%end_no4% set /a ip_rules=0 & goto error2
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% gtr %end_no3% if /i %start_no4% gtr %end_no4% set /a ip_rules=0 & goto error2

:condition3-2
::classB-2
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set ip_on1=%start_no1%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set ip_on2=%start_no2%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set ip_on3=%start_no3%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set ip_on4=%start_no4%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set ip_on5=%end_no3%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set ip_on6=%end_no4%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% echo 符合condition3-2
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% lss %end_no3% if /i %start_no4% lss %end_no4% set /a ip_rules=6
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% gtr %end_no3% if /i %start_no4% lss %end_no4% set /a ip_rules=0 & goto error2
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3% gtr %end_no3% if /i %start_no4% gtr %end_no4% set /a ip_rules=0 & goto error2
:condition4-1
::classC
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4% lss %end_no4% set ip_on1=%start_no1%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4% lss %end_no4% set ip_on2=%start_no2%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4% lss %end_no4% set ip_on3=%start_no3%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4% lss %end_no4% set ip_on4=%start_no4%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4% lss %end_no4% set ip_on5=%end_no4%
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4% lss %end_no4% echo 符合condition4-1
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4% lss %end_no4% set /a ip_rules=7
if /i %start_no1%==%end_no1% if /i %start_no2%==%end_no2% if /i %start_no3%==%end_no3% if /i %start_no4% gtr %end_no4% set /a ip_rules=0 & goto error2


goto :eof
:error1
echo 輸入之IP ADDRESS規則有誤,請重新輸入。
pause>unl
goto :eof
:error2
echo 開始區段不得大於結束區段,程序將關閉。
pause>unl
goto :eof
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
PPdos +4 2007-02-22 20:25
2 发表于 2007-02-21 23:12 ·  中国 四川 成都 电信
铂金会员
★★★★
积分 7,493
发帖 2,672
注册 2005-09-02 00:00
UID 42173
性别 男
状态 离线
好整齐的p处理!

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'>"
3 发表于 2007-02-21 23:55 ·  中国 安徽 芜湖 电信
高级用户
★★★
积分 866
发帖 415
注册 2005-12-04 11:19
UID 46459
状态 离线
楼主真有干劲。
4 发表于 2007-02-22 00:20 ·  中国 安徽 芜湖 电信
高级用户
★★★
积分 866
发帖 415
注册 2005-12-04 11:19
UID 46459
状态 离线
::判斷輸入規則是否大於255,若大於255則進位
if /i %start_no1% gtr 255 set /a start_no2=start_no2+1
if /i %start_no2% gtr 255 set /a start_no3=start_no3+1
if /i %start_no3% gtr 255 set /a start_no4=start_no4+1
if /i %start_no1% gtr 255 set /a start_no1=255
if /i %start_no2% gtr 255 set /a start_no2=255
if /i %start_no3% gtr 255 set /a start_no3=255

水平有限,对这个不是很理解。
5 发表于 2007-02-22 07:12 ·  中国 台湾
初级用户
积分 52
发帖 21
注册 2006-01-04 20:41
UID 48443
状态 离线
Originally posted by htysm at 2007-2-22 00:20:
::判斷輸入規則是否大於255,若大於255則進位
if /i %start_no1% gtr 255 set /a start_no2=start_no2+1
if /i %start_no2% gtr 255 set /a start_no3=start_no3+1
if /i %start_no3% gtr 25 ...

這本來是要用來進位用~
因為ip address到255就會進位
只是代碼並未完成.....
所以對class c而言
並未有影響。
6 发表于 2007-02-22 07:16 ·  中国 台湾
初级用户
积分 52
发帖 21
注册 2006-01-04 20:41
UID 48443
状态 离线
Originally posted by htysm at 2007-2-22 00:20:
::判斷輸入規則是否大於255,若大於255則進位
if /i %start_no1% gtr 255 set /a start_no2=start_no2+1
if /i %start_no2% gtr 255 set /a start_no3=start_no3+1
if /i %start_no3% gtr 25 ...

這本來是要用來進位用~
因為ip address到255就會進位
只是代碼並未完成.....
所以對class c而言
並未有影響。
7 发表于 2007-02-22 16:45 ·  中国 广东 广州 电信
初级用户
★★
积分 197
发帖 77
注册 2006-09-19 14:02
UID 63074
性别 男
状态 离线
虽然没全看懂先顶
8 鼓励创作 发表于 2007-02-22 20:27 ·  新西兰 奥克兰大区 奥克兰 Microsoft
高级用户
★★
积分 783
发帖 268
注册 2006-12-26 17:18
UID 74627
性别 男
状态 离线
但应注意细节 比如 nul 非 unl
菩提本无树,明镜亦非台,本来无一物,何处惹尘埃.
9 发表于 2007-03-04 12:40 ·  中国 台湾 索尼So-Net娱乐通讯
初级用户
积分 52
发帖 21
注册 2006-01-04 20:41
UID 48443
状态 离线
Originally posted by bbq123bbq at 2007-2-22 16:45:
虽然没全看懂先顶

是的~感謝兄的指教,這的確是不該犯的小錯誤
论坛跳转: