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

[网络连接] 批处理如何登陆交换机后ping多台主机?

很多时候我们可能要登陆到cisco交换机执行一些常规的查看命令,但是每次又要cmd,输入密码,输入命令感觉麻烦。

发现其实可以通过建立批处理来实现,如登陆到cisco交换机192.168.0.1然后ping另外一台交换机192.168.0.2

脚本如下:

@echo off
echo set sh=WScript.CreateObject("WScript.Shell") >telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo sh.SendKeys "open 192.168.0.1" >>telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo sh.SendKeys "{ENTER}" >>telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo sh.SendKeys "root{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo sh.SendKeys "YOUR_PASSWORD{ENTER}">>telnet_tmp.vbs
echo sh.SendKeys "ping 192.168.0.2{ENTER}" >>telnet_tmp.vbs
start telnet
cscript //nologo telnet_tmp.vbs
echo del telnet_tmp.vbs


此代码可以正常执行,但是我现在想ping多个IP地址,该怎样实现,另外我想把多个IP地址存放在文本文件内,供此程序调用,最后将ping的结果保留在新建的文本文件内

哪位高手帮忙解决一下,谢谢

哪位高手帮忙解决一下啊

TOP

  1. @echo off&TITLE cody by bathome_breakme
  2. echo set sh=WScript.CreateObject("WScript.Shell") >telnet_tmp.vbs
  3. echo WScript.Sleep 300 >>telnet_tmp.vbs
  4. echo sh.SendKeys "open 168.30.6.104" >>telnet_tmp.vbs
  5. echo WScript.Sleep 300 >>telnet_tmp.vbs
  6. echo sh.SendKeys "{ENTER}" >>telnet_tmp.vbs
  7. echo WScript.Sleep 300 >>telnet_tmp.vbs
  8. echo sh.SendKeys "root{ENTER}">>telnet_tmp.vbs
  9. echo WScript.Sleep 300 >>telnet_tmp.vbs
  10. echo sh.SendKeys "YOUR_PASSWORD{ENTER}">>telnet_tmp.vbs
  11. for /f "" %%i in (serverip.txt) do call :telping %%i
  12. start telnet -f c:\telping.txt
  13. cscript //nologo telnet_tmp.vbs
  14. taskkill /im telnet.exe /f>nul
  15. del /f telnet_tmp.vbs >nul
  16. start notepad c:\telping.txt
  17. exit
  18. :telping
  19. echo sh.SendKeys "ping %1 {ENTER}" >>telnet_tmp.vbs
  20. echo WScript.Sleep 8000 >>telnet_tmp.vbs
  21. exit /b
复制代码

TOP

解释:
start telnet -f c:\telping.txt
是表示 日志文件路径:c:\telping.txt
for /f "" %%i in (serverip.txt) do call :telping %%i
serverip.txt 是 ip 列表,一行一个ip 无空格等字符
上面主要作用,有多少个IP就生成多少行 ping ip
echo WScript.Sleep 8000 >>telnet_tmp.vbs
是ping ip  的延迟命令,时间一定要足,否则可能会出错

TOP

返回列表