标题: [网络连接] [已解决]批处理怎样去掉ping输出的不需要的内容和增加声音? [打印本页]
作者: smartztech 时间: 2010-5-14 17:34 标题: [已解决]批处理怎样去掉ping输出的不需要的内容和增加声音?
新手,刚看到贵论坛。学习中。
公司进了批设备交给小弟测试,一直盯着看太费眼,希望做个文件实现以下功能:
每隔5秒ping一次192.168.1.1 结果形成文件。
问题是:1、不知道怎么实现时间间隔,
2、输出结果里不需要出现
Ping statistics for 192.168.1.1:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 2ms, Maximum = 2ms, Average = 2ms
补充:如果不通的时候可以声音提示。不知道怎样出现声音
谢谢。在线等
[ 本帖最后由 smartztech 于 2010-5-20 09:50 编辑 ]
作者: smartztech 时间: 2010-5-14 18:08
- @echo off
- :a
- echo Wscript.Sleep Wscript.Arguments(0) * 1000>Delay.vbs
- Delay.vbs 5
- echo OK!
- echo %date% %time% >>log.txt
- ping 192.168.1.1 -n 1 >>log.txt
- goto a
复制代码
出来的log.txt2010-05-14 星期五 18:05:16.56
Pinging 192.168.1.1 with 32 bytes of data:
Reply from 192.168.1.1: bytes=32 time=1ms TTL=64
Ping statistics for 192.168.1.1:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 1ms, Average = 1ms
2010-05-14 星期五 18:05:22.34
Pinging 192.168.1.1 with 32 bytes of data:
Reply from 192.168.1.1: bytes=32 time=1ms TTL=64
Ping statistics for 192.168.1.1:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 1ms, Average = 1ms
请教怎样将log.txt文件中的Ping statistics for 192.168.1.1:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 1ms, Average = 1ms
这部分去掉!否则生成的文件太大。
还有声音文件正在学习中。
谢谢。
作者: hanyeguxing 时间: 2010-5-14 18:57
使用重定向操作,屏蔽标准输出为>nul,屏蔽错误输出为 2>nul- @echo off
- echo.strSoundFile = "%SystemRoot%\Media\Windows XP 注销音.wav">hanye.vbs
- echo.Set objShell = CreateObject("Wscript.Shell")>>hanye.vbs
- echo.strCommand = "sndrec32 /play /close " ^& chr(34) ^& strSoundFile ^& chr(34)>>hanye.vbs
- echo.objShell.Run strCommand, 0, True>>hanye.vbs
- :s
- ping -n 6 127.1 >nul 2>nul
- ping -n 1 192.168.1.1 >nul 2>nul||cscript //nologo hanye.vbs
- goto:s
复制代码
或:- @echo off
- :s
- ping -n 6 127.1 >nul 2>nul
- ping -n 1 192.168.1.1 >nul 2>nul||start "" "%ProgramFiles%\Ringz Studio\Storm Codec\mplayerc.exe" /play /close /minimized "G:\Documents\My Music\What Becomes Of Us.mp3"
- goto:s
复制代码
其中%ProgramFiles%\Ringz Studio\Storm Codec\mplayerc.exe为暴风影音
[ 本帖最后由 hanyeguxing 于 2010-5-14 19:06 编辑 ]
作者: smartztech 时间: 2010-5-14 19:44
非常感谢hanyeguxing,播放声音总算是出来了。
但我需要txt文件里有每次ping的时间和返回正确或者返回错误的信息,
需要出现
Reply from 192.168.1.1: bytes=32 time=1ms TTL=64
或者
Request timed out
但不要出现
Ping statistics for 192.168.1.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 1ms, Average = 1ms
这一部分内容。
再次感谢
作者: hanyeguxing 时间: 2010-5-15 10:10
- @echo off
- more +8<%~fs0>hanye.vbs
- :s
- ping -n 6 127.1 >nul 2>nul
- ping -n 1 192.168.1.2 >$temp$ 2>&1
- if ERRORLEVEL 1 cscript //nologo hanye.vbs
- (for /f "tokens=1* delims=:" %%a in ('findstr /n .* $temp$') do if %%a==4 echo.%date% %time%&echo.%%b)>>日志.log
- goto:s
- strSoundFile = "%SystemRoot%\Media\Windows XP 注销音.wav"
- Set objShell = CreateObject("Wscript.Shell")
- strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
- objShell.Run strCommand, 0, True
复制代码
[ 本帖最后由 hanyeguxing 于 2010-5-15 10:13 编辑 ]
作者: hanyeguxing 时间: 2010-5-15 10:21
- @echo off
- set "hanye="%ProgramFiles%\Ringz Studio\Storm Codec\mplayerc.exe" /play /close /minimized "G:\Documents\My Music\What Becomes Of Us.mp3""
- :s
- ping -n 6 127.1 >nul 2>nul
- ping -n 1 192.168.1.2 >$temp$ 2>&1
- if ERRORLEVEL 1 start "" %hanye%
- (for /f "tokens=1* delims=:" %%a in ('findstr /n .* $temp$') do if %%a==4 echo.%date% %time%&echo.%%b)>>日志.log
- goto:s
复制代码
作者: smartztech 时间: 2010-5-20 09:49
谢谢!解决!
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |