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

[文件操作] 求助批处理怎样把字符串直接填到下个语句的需要的地方?

是某个工具,分两次执行,我嫌麻烦,准备一步到位,请教下:

echo sh.SendKeys "cat /var/tel_passwd | head -n 2 | tail -n 1 | cut -d : -f 2{ENTER}" >>telnet_tmp.vbs

这时得到"XXXXXXXX"字符串,怎样把这字符串直接填到下个语句的需要的地方?
  1. arp -d
  2. echo set sh=WScript.CreateObject("WScript.Shell") >telnet_tmp.vbs
  3. echo WScript.Sleep 300 >>telnet_tmp.vbs
  4. echo sh.SendKeys "open 192.168.1.1{ENTER}" >>telnet_tmp.vbs
  5. echo WScript.Sleep 300 >>telnet_tmp.vbs
  6. echo sh.SendKeys "useradmin{ENTER}" >>telnet_tmp.vbs
  7. echo WScript.Sleep 1000 >>telnet_tmp.vbs
  8. echo sh.SendKeys "useradmin{ENTER}" >>telnet_tmp.vbs
  9. echo WScript.Sleep 300 >>telnet_tmp.vbs
  10. echo sh.SendKeys "cat /var/tel_passwd | head -n 2 | tail -n 1 | cut -d : -f 2{ENTER}" >>telnet_tmp.vbs
  11. echo WScript.Sleep 300 >>telnet_tmp.vbs
  12. echo sh.SendKeys "root{ENTER}" >>telnet_tmp.vbs
  13. echo WScript.Sleep 1000 >>telnet_tmp.vbs
  14. echo sh.SendKeys "XXXXXXXX{ENTER}" >>telnet_tmp.vbs
  15. echo WScript.Sleep 300 >>telnet_tmp.vbs
复制代码

回复  ghj7205

订正了6楼代码,改为用 sed.exe 自动匹配首尾标识行来切割当前批处脚本以分别生成两个 v ...
aloha20200628 发表于 2024-12-20 21:22



    运行不下去哦
窗口显示Microsotf Telnet>
就停止了

怎么图片发送不了,少于50k了啊?说不能保存

TOP

好的,我明天试试看,谢谢指教🤝

TOP

回复 5# ghj7205

订正了6楼代码,改为用 sed.exe 自动匹配首尾标识行来切割当前批处脚本以分别生成两个 vbs 脚本...

TOP

本帖最后由 aloha20200628 于 2024-12-20 22:12 编辑

回复 1# ghj7205

   以下代码存为 test.bat 运行,其中改变了临时创建 *.vbs 脚本的方法,调用 sed.exe(与楼主vbs脚本中采用的 cat/cut/.. 同属gnu系列工具)直接分割当前批处脚本(自动匹配各段首尾标识行)即可...
   中间单独运行 cat ... cut ... 以便回收其密码生成值 %p%,并用 sed.exe 替换到第二段 vbs 脚本所需的*字段位置...
  1. @echo off &setlocal
  2. arp -d
  3. sed.exe -n "/'' telnet_tmp2.vbs/I,/'' end_1/I p" "%~f0">telnet_tmp1.vbs
  4. start "" telnet
  5. cscript //nologo telnet_tmp1.vbs
  6. cat /var/tel_passwd | head -n 2 | tail -n 1 | cut -d : -f 2>telnet_tmp0.vbs
  7. set/p "p="<telnet_tmp0.vbs
  8. sed.exe -n "/'' telnet_tmp2.vbs/I,/'' end_2/I p" "%~f0"|sed.exe -r "s/\*/%p%/">telnet_tmp2.vbs
  9. arp -d
  10. cscript //nologo telnet_tmp2.vbs
  11. del /q "telnet_tmp?.vbs" &pause&exit/b
  12. '' telnet_tmp1.vbs
  13. set sh=WScript.CreateObject("WScript.Shell")
  14. WScript.Sleep 300
  15. sh.SendKeys "open 192.168.1.1{ENTER}"
  16. WScript.Sleep 300
  17. sh.SendKeys "useradmin{ENTER}"
  18. WScript.Sleep 1000
  19. sh.SendKeys "abcd{ENTER}"
  20. WScript.Sleep 300
  21. '' end_1
  22. '' telnet_tmp2.vbs
  23. set sh=WScript.CreateObject("WScript.Shell")
  24. WScript.Sleep 300
  25. sh.SendKeys "open 192.168.1.1{ENTER}"
  26. WScript.Sleep 300
  27. sh.SendKeys "root{ENTER}"
  28. WScript.Sleep 1000
  29. sh.SendKeys "*{ENTER}"
  30. WScript.Sleep 300
  31. '' end_2
复制代码

TOP

得到"XXXXXXXX"字符串
哪里得到的?完全看不出来
czjt1234 发表于 2024-12-20 15:53


这是第一个运行BAT
arp -d
echo set sh=WScript.CreateObject("WScript.Shell") >telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo sh.SendKeys "open 192.168.1.1{ENTER}" >>telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo sh.SendKeys "useradmin{ENTER}" >>telnet_tmp.vbs
echo WScript.Sleep 1000 >>telnet_tmp.vbs
echo sh.SendKeys "abcd{ENTER}" >>telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo sh.SendKeys "cat /var/tel_passwd | head -n 2 | tail -n 1 | cut -d : -f 2{ENTER}" >>telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
start telnet
cscript //nologo telnet_tmp.vbs
del telnet_tmp.vbs

运行结果是zqg93dkych7x7


这是第二个BAT
arp -d
echo set sh=WScript.CreateObject("WScript.Shell") >telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo sh.SendKeys "open 192.168.1.1{ENTER}" >>telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo sh.SendKeys "root{ENTER}" >>telnet_tmp.vbs
echo WScript.Sleep 1000 >>telnet_tmp.vbs
echo sh.SendKeys "zqg93dkych7x7{ENTER}" >>telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs

TOP

得到"XXXXXXXX"字符串
哪里得到的?完全看不出来
czjt1234 发表于 2024-12-20 15:53



    运行第10句后会在CMD窗口显示运行结果,就是一个字符串,“root”后换行需要填写密码,这个字符串就是密码

TOP

得到"XXXXXXXX"字符串
哪里得到的?完全看不出来

QQ 20147578

TOP

感谢大家

TOP

返回列表