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

[文本处理] 利用批处理将能Ping通的IP地址记录下来

试着编写了一个文件,Ping指定段的IP地址,目前能够自动处理,将Ping的情况的记录下来,现在想在后面加一些命令,只记录能Ping通的IP,而不能Ping通的不作记录。
初学批处理命令,请高手指点。
  1. @Echo off
  2.   date /t > IPList.txt
  3.   time /t >> IPList.txt
  4.   echo =========== >> IPList.txt
  5.   For /L %%G in (200,1,254) Do Ping.exe -n 1 192.168.1.%%G >>IPList.txt
  6.  exit
复制代码

本帖最后由 lifei259 于 2017-11-17 15:17 编辑
  1. @Echo off
  2.   date /t > IPList.txt
  3.   time /t >> IPList.txt
  4.   echo =========== >> IPList.txt
  5.   For /L %%G in (200,1,254) Do (
  6.             for /f "delims="  %%a  in ('Ping -n 1 192.168.1.%%G^|findstr /i "TTL"')  do (
  7.             echo,%%a >>IPList.txt
  8.            )
  9.       )
  10.  exit
复制代码

TOP

回复 2# lifei259


    太感谢了。这样不用进路由器就能知道哪些电脑在线。非常感谢。==

TOP

回复 2# lifei259


    想ip地址从一个文件(list.txt)里取值怎么做啊?

TOP

回复 4# conan52


假定list.txt每行一个IP地址
  1. @echo off
  2. > iplist.txt date /t
  3. >> iplist.txt time /t
  4. >> iplist.txt echo ===========
  5. (for /f %%g in ('type "list.txt"') do (
  6.     for /f "delims=" %%a in ('ping -n 1 %%g ^| findstr /i "ttl"') do (
  7.         echo,%%a
  8.     )
  9. ))>>iplist.txt
复制代码
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

回复 5# Batcher


好像运行不了?cmd窗口停在那里,没有反应。

TOP

回复 6# conan52


代码生成的iplist.txt里面有什么内容吗?

参考Q-01的方法试试:
https://mp.weixin.qq.com/s/6lbb97qUOs1sTyKJfN0ZEQ
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

本帖最后由 Gin_Q 于 2020-4-15 19:29 编辑
  1. @echo off&setlocal enabledelayedexpansion
  2. ::192.168.1.1
  3. echo "Pls Wait..."
  4. date /t > IPList.txt
  5. time /t >> IPList.txt
  6. for /f "tokens=*" %%a in ('type "list.txt"') do (ping %%a -n 1 1>nul
  7. if !errorlevel! EQU 0 echo %%a)>>IPList.txt
  8. echo "Done!"
  9. pause
复制代码

TOP

回复 7# Batcher


  可以使用。  不好意思,是cmd窗口没有回显,我的list.txt里面的内容也比较多,所有感觉半天没反应。谢谢!

TOP

返回列表