|
yc421206
初级用户
 
积分 52
发帖 21
注册 2006-1-4
状态 离线
|
   『楼 主』:
IP區段掃瞄 目前適用ClassC
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
此帖被 +4 点积分 点击查看详情 评分人:【 PPdos 】 | 分数: +4 | 时间:2007-2-22 20:25 |
|
|
|
2007-2-21 14:22 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第
2 楼』:
好整齐的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'>" |
|
2007-2-21 23:12 |
|
|
htysm
高级用户
   
积分 866
发帖 415
注册 2005-12-4
状态 离线
|
|
2007-2-21 23:55 |
|
|
htysm
高级用户
   
积分 866
发帖 415
注册 2005-12-4
状态 离线
|
『第
4 楼』:
::判斷輸入規則是否大於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
水平有限,对这个不是很理解。
|
|
2007-2-22 00:20 |
|
|
yc421206
初级用户
 
积分 52
发帖 21
注册 2006-1-4
状态 离线
|
『第
5 楼』:
Quote: | 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而言
並未有影響。
|
|
2007-2-22 07:12 |
|
|
yc421206
初级用户
 
积分 52
发帖 21
注册 2006-1-4
状态 离线
|
『第
6 楼』:
Quote: | 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而言
並未有影響。
|
|
2007-2-22 07:16 |
|
|
bbq123bbq
初级用户
 
积分 197
发帖 77
注册 2006-9-19
状态 离线
|
|
2007-2-22 16:45 |
|
|
PPdos
高级用户
   
积分 783
发帖 268
注册 2006-12-26
状态 离线
|
『第
8 楼』:
鼓励创作
但应注意细节 比如 nul 非 unl
|

菩提本无树,明镜亦非台,本来无一物,何处惹尘埃. |
|
2007-2-22 20:27 |
|
|
yc421206
初级用户
 
积分 52
发帖 21
注册 2006-1-4
状态 离线
|
『第
9 楼』:
Quote: | Originally posted by bbq123bbq at 2007-2-22 16:45:
虽然没全看懂先顶 |
|
是的~感謝兄的指教,這的確是不該犯的小錯誤
|
|
2007-3-4 12:40 |
|