[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[网络连接] [已解决]批处理如何提取ping命令结果的指定信息?

是这么一个事情……
我突然想试试自己学到一个什么程度了。于是在百度上去回答问题,有一个问题是:
在一个文本里有若干的IP地址。
写一个批处理依次对其进行ping处理。(::这个我还是能做得出来的,嘻嘻……)
对结果进行处理。要求提取出所有能ping通的IP。(::就是这,我不能有效的提取出来……)
亲爱的大大些。仁慈如您们的人,一定会不吝赐教的,对吧!
嘻嘻!谢谢各位大大!在我的成长路上,希望有诸位的见证……
求符合要求的代码以供小菜研究!
不胜感激,感激涕零啊大大!
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

ping www.bathome.net&&echo 成功||echo 失败
1

评分人数

TOP

for /f %%i in (1XXX.txt) do (
set /a n+=1
ping %%i
if %errorlevel%==0 echo %%i>>2XXX.txt
)
1XXX.txt是你装IP的文件
2XXX.txt是可以平通的文件,能PING通的都在里面

TOP

回复 3# 秋风·飞扬


    哦 上面没有set /a n+=1 这句没用,我忘删掉了

TOP

回复 1# lijinpengying


    互相帮助,尽力而为,。

TOP

如果问题解决,就在标题上修改【已解决】

TOP

代码需要改,先等一下吧

TOP

回复 7# 秋风·飞扬


    代码是错误的。因为无论如何ping命令都是成功执行的,所以你这个代码是不可能判断出哪些能拼通哪些不能。唉……
我记得以前见过正确的代码,可是忘了在哪里看到的了。好像是利用了findstr命令。

TOP

@echo off &setlocal enabledelayedexpansion
for /f %%i in (ip.txt) do (
set ip=%%i
ping /n 1 !ip! | findstr /i "reply"&&if errorlevel==0 echo !ip! >>now.txt
)

解决啦!嘻嘻!

TOP

回复 8# lijinpengying


    对不起啊,真是不好意思,我下午去上课了,那个代码 for循环里面的两句合并为一句,ping /n 2 %%i && echo %%i >>2.txt 即可,sorry~

TOP

根据这个改吧,作者QQ:2294394563
  1. @echo off
  2. set pingTimes=1
  3. if "%1"=="/?" (
  4. echo Usage: %~n0 [-f filename] [-o filename] domain [-call skip lines ^| -t Threads_NUM All_lines]
  5. echo Options:
  6. echo     -f     Dict file used to brute sub names.
  7. echo            Default:resolvers.txt
  8. echo     -o     Output file name.
  9. echo     -t     Number of threads and lines.
  10. rem echo     -call  emm...
  11. echo;
  12. echo 20171003
  13. exit /b
  14. )
  15. :0
  16. if "%1"=="-f" (
  17. set resolvers=%~2
  18. shift
  19. shift
  20. goto 0
  21. )
  22. if not defined resolvers set resolvers=resolvers.txt
  23. if not exist "%resolvers%" (
  24. echo Can't found "%resolvers%".
  25. exit /b
  26. )
  27. if "%1"=="-o" (
  28. set output=%~2
  29. shift
  30. shift
  31. goto 0
  32. )
  33. if not defined output set output=nul
  34. set domain=%~1
  35. if "%2"=="-t" (
  36. if "%output%"=="nul" (
  37. echo Output file is not specified.
  38. exit /b
  39. )
  40. set /a threads=%3-1
  41. set allLines=%4
  42. setlocal enabledelayedexpansion
  43. if !threads! lss 0 (
  44. echo Threads leq 0!
  45. exit /b
  46. )
  47. if !allLines! lss !threads! (
  48. echo All_lines lss Threads_NUM!
  49. exit /b
  50. )
  51. set /a lines=allLines/(threads+1^)
  52. for /l %%a in (1,1,!threads!) do (
  53. set /a skip=%%a*lines
  54. start "SubBrute Threads:%%a" subbrute -o "%output%" -f "%resolvers%" %domain% -call !skip! !lines! >nul
  55. )
  56. title SubBrute Threads:0
  57. echo All threads are running.
  58. )
  59. if "%2"=="-call" (
  60. if "%output%"=="nul" (
  61. echo Output file is not specified.
  62. exit /b
  63. )
  64. setlocal enabledelayedexpansion
  65. set skip=%3
  66. if !skip! leq 0 (
  67. echo Skip leq 0!
  68. exit /b
  69. )
  70. set times=%4
  71. shift
  72. shift
  73. shift
  74. for /f "usebackq skip=%skip%" %%a in ("%resolvers%") do (
  75. ping /n %pingTimes% %%a.%domain% >nul 2>nul
  76. if !errorlevel!==0 (
  77. echo %%a.%domain%
  78. echo %%a.%domain% >>"%output%"
  79. )
  80. set /a times-=1
  81. if "!times!"=="0" exit
  82. )
  83. )
  84. if defined lines setlocal enabledelayedexpansion
  85. set scan=0
  86. set found=0
  87. for /f usebackq %%a in ("%resolvers%") do (
  88. ping /n %pingTimes% %%a.%domain% >nul 2>nul
  89. if !errorlevel!==0 (
  90. echo %%a.%domain%
  91. echo %%a.%domain% >>"%output%"
  92. set /a found+=1
  93. )
  94. set /a scan+=1
  95. set /a lines-=1
  96. if !lines!==0 exit
  97. )
  98. echo;
  99. echo %found% found ^| %scan% sacnned
  100. exit /b
复制代码

TOP

返回列表