寻找Windows的batch file,它将远程login到一个IP地址,自动提供batch file中指定的用户名和密码,执行一系列命令并退出telnet。
@echo off SET username=abc SET password=xyz@1234 SET servername=192.168.1.40 echo user %username%> telnetcmd.dat echo %password%>> telnetcmd.dat echo adbd^& >> telnetcmd.dat echo exit>> telnetcmd.dat telnet %servername% < telnetcmd.dat del telnetcmd.dat
在这里,我正在尝试使用用户名和密码进行telnet到IP。 成功login后,应执行adbc&(这将在后台运行必要的服务)命令和退出命令。 一旦我完成这个batch file,如果我检查在服务器上运行的adbc服务,它显示不在服务器上运行 。
输出我正在完成batch file后。
Welcome to Microsoft Telnet Client Escape Character is 'CTRL+]' c:\Users\vshah\Desktop>
预期产出:
root@pqrs:/ # ps | grep adbd shell 31899 31828 1348 148 ffffffff 00013348 S adbd
执行batch file后的实际输出:
root@pqrs:/ # ps | grep adbd 1|root@pqrs:/ #
请帮助我实现这种情况。
非常感谢您提前。
它实际上不是批处理,而是一个vbscript,它使用睡眠,所以在高延迟的情况下,它很容易失败,但我已经使用以下脚本来测试通过telnet发送电子邮件
smtpadr = InputBox("SMTP server address", "","192.168.1.35" , 100, 200) localname = InputBox("SMTP", "","mx01.domain.com" , 100, 200) emailadr = InputBox("Email address", "","jonbdk@domain.com" , 100, 200) if smtpadr & "" = "" OR localname & "" = "" OR emailadr & "" = "" then wscript.quit end if set Shell=CreateObject("WScript.Shell") Shell.run "cmd /K" wscript.sleep(1000) sendkeys ("telnet "&smtpadr&" 25{ENTER}") wscript.sleep(4000) 'sendkeys ("quit{ENTER}") sendkeys ("HELO "&localname&"{ENTER}") wscript.sleep(2000) sendkeys ("MAIL FROM:<"&emailadr&">{ENTER}") wscript.sleep(1000) sendkeys ("RCPT TO:<"&emailadr&">{ENTER}") wscript.sleep(1000) sendkeys ("DATA{ENTER}") wscript.sleep(1000) sendkeys ("FROM:<"&emailadr&">{ENTER}") wscript.sleep(100) sendkeys ("TO:<"&emailadr&">{ENTER}") wscript.sleep(100) sendkeys ("Date:16-05-2010{ENTER}") wscript.sleep(100) sendkeys ("{ENTER}") wscript.sleep(100) sendkeys ("Hello World{ENTER}") wscript.sleep(100) sendkeys (".{ENTER}") function sendkeys (strkeys) on error resume next ' BACKSPACE {BACKSPACE}, {BS}, or {BKSP} ' BREAK {BREAK} ' CAPS LOCK {CAPSLOCK} ' DEL or DELETE {DELETE} or {DEL} ' DOWN ARROW {DOWN} ' END {END} ' ENTER {ENTER} or ~ ' ESC {ESC} ' HELP {HELP} ' HOME {HOME} ' INS or INSERT {INSERT} or {INS} ' LEFT ARROW {LEFT} ' NUM LOCK {NUMLOCK} ' PAGE DOWN {PGDN} ' PAGE UP {PGUP} ' PRINT SCREEN {PRTSC} ' RIGHT ARROW {RIGHT} ' SCROLL LOCK {SCROLLLOCK} ' TAB {TAB} ' UP ARROW {UP} ' F1 {F1} shell.sendkeys(strKeys) if err.number <> 0 then debug "Failed to sendkeys """ & strkeys &"""" on error goto 0 end function