标题: 哪位指导我一下如何用for
[打印本页]
作者: wqh
时间: 2008-4-10 15:18
标题: 哪位指导我一下如何用for
想写个这样的批处理
加入5台电脑ip分别为
192.168.0.2
192.168.0.9
192.168.0.10
192.168.0.20
192.168.0.41
不是连续的ip地址
#---------------------------------------------------------------
@echo off
ping 192.168.0.2|find "Reply"
if not errorlevel 1 net send 192.168.0.1 I'm Down!
ping 192.168.0.9|find "Reply"
if not errorlevel 1 net send 192.168.0.1 I'm Down!
ping 192.168.0.10|find "Reply"
if not errorlevel 1 net send 192.168.0.1 I'm Down!
ping 192.168.0.20|find "Reply"
if not errorlevel 1 net send 192.168.0.1 I'm Down!
ping 192.168.0.41|find "Reply"
if not errorlevel 1 net send 192.168.0.1 I'm Down!
#----------------------------------------------------------------
5台电脑可以这样,如果有上几十台上百台,这样写就比较笨了
我就尝试用for语句来实现
把那5个ip分行写道iplist.txt
然后
#----------------------------------------------------------------
@Echo off
for /F %%i in (iplist.txt) do (
ping %%i|find "Reply"
if not errorlevel 1 net send 192.168.0.1 I'm Down!
)
#----------------------------------------------------------------
因为对for不是很熟,我是想当然写的,所以运行明显有异常
哪位帮我改改
作者: bigfaint
时间: 2008-4-10 15:31
需要启用变量延迟的
这样写
@Echo off&setlocal EnableDelayedExpansion
for /F %%i in (iplist.txt) do (
ping %%i|find "Reply"
if not errorlevel 1 net send %%i I'm Down!
)
感觉你写反了,你应该是记录没有开机的电脑吧,那么你应该写if errorlevel 1 net sent...
作者: wqh
时间: 2008-4-10 16:38
谢谢楼上的大哥