Board logo

标题: [文本处理] 利用批处理将能Ping通的IP地址记录下来 [打印本页]

作者: lichun8241    时间: 2017-11-17 14:58     标题: 利用批处理将能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:15

本帖最后由 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
复制代码

作者: lichun8241    时间: 2017-11-17 15:38

回复 2# lifei259


    太感谢了。这样不用进路由器就能知道哪些电脑在线。非常感谢。==
作者: conan52    时间: 2020-4-15 14:58

回复 2# lifei259


    想ip地址从一个文件(list.txt)里取值怎么做啊?
作者: Batcher    时间: 2020-4-15 15:12

回复 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
复制代码

作者: conan52    时间: 2020-4-15 15:37

回复 5# Batcher


好像运行不了?cmd窗口停在那里,没有反应。
作者: Batcher    时间: 2020-4-15 15:41

回复 6# conan52


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

参考Q-01的方法试试:
https://mp.weixin.qq.com/s/6lbb97qUOs1sTyKJfN0ZEQ
作者: Gin_Q    时间: 2020-4-15 19:22

本帖最后由 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
复制代码

作者: conan52    时间: 2020-4-16 08:47

回复 7# Batcher


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




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2