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

[网络连接] [已解决]批处理怎样去掉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 编辑 ]
1

评分人数

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

  1. @echo off
  2. :a
  3. echo Wscript.Sleep Wscript.Arguments(0) * 1000>Delay.vbs
  4. Delay.vbs 5  
  5. echo OK!
  6. echo %date% %time% >>log.txt
  7. ping 192.168.1.1 -n 1 >>log.txt
  8. goto a
复制代码
出来的log.txt
2010-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
这部分去掉!否则生成的文件太大。
还有声音文件正在学习中。
谢谢。

TOP

使用重定向操作,屏蔽标准输出为>nul,屏蔽错误输出为 2>nul
  1. @echo off
  2. echo.strSoundFile = "%SystemRoot%\Media\Windows XP 注销音.wav">hanye.vbs
  3. echo.Set objShell = CreateObject("Wscript.Shell")>>hanye.vbs
  4. echo.strCommand = "sndrec32 /play /close " ^& chr(34) ^& strSoundFile ^& chr(34)>>hanye.vbs
  5. echo.objShell.Run strCommand, 0, True>>hanye.vbs
  6. :s
  7. ping -n 6 127.1 >nul 2>nul
  8. ping -n 1 192.168.1.1 >nul 2>nul||cscript //nologo hanye.vbs
  9. goto:s
复制代码
或:
  1. @echo off
  2. :s
  3. ping -n 6 127.1 >nul 2>nul
  4. 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"
  5. goto:s
复制代码
其中%ProgramFiles%\Ringz Studio\Storm Codec\mplayerc.exe为暴风影音

[ 本帖最后由 hanyeguxing 于 2010-5-14 19:06 编辑 ]
寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

非常感谢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
这一部分内容。

再次感谢

TOP

  1. @echo off
  2. more +8<%~fs0>hanye.vbs
  3. :s
  4. ping -n 6 127.1 >nul 2>nul
  5. ping -n 1 192.168.1.2 >$temp$ 2>&1
  6. if ERRORLEVEL 1 cscript //nologo hanye.vbs
  7. (for /f "tokens=1* delims=:" %%a in ('findstr /n .* $temp$') do if %%a==4 echo.%date% %time%&echo.%%b)>>日志.log
  8. goto:s
  9. strSoundFile = "%SystemRoot%\Media\Windows XP 注销音.wav"
  10. Set objShell = CreateObject("Wscript.Shell")
  11. strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
  12. objShell.Run strCommand, 0, True
复制代码

[ 本帖最后由 hanyeguxing 于 2010-5-15 10:13 编辑 ]
寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

  1. @echo off
  2. set "hanye="%ProgramFiles%\Ringz Studio\Storm Codec\mplayerc.exe" /play /close /minimized "G:\Documents\My Music\What Becomes Of Us.mp3""
  3. :s
  4. ping -n 6 127.1 >nul 2>nul
  5. ping -n 1 192.168.1.2 >$temp$ 2>&1
  6. if ERRORLEVEL 1 start "" %hanye%
  7. (for /f "tokens=1* delims=:" %%a in ('findstr /n .* $temp$') do if %%a==4 echo.%date% %time%&echo.%%b)>>日志.log
  8. goto:s
复制代码
1

评分人数

寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

谢谢!解决!

TOP

返回列表