开发者

How can I open a cmd window and pass in hardcoded values using a batch file?

I have found many solutions that are close to what I want but not exactly it and have had no luck myself.

I am trying to create a script that I can use to automate firewall authentication. I am doing this manually at the minute by opening a cmd window and attempting to telnet to a device/pc behind the firewall. After a short pause I am prompted for username and password.

Is there any way to write a batch file that will open a cmd window and provide these two values?

Currently it goes like this:

C:> telnet device (I type this in to prompt authentication)
(short pause)
-- Firewall Authentication --
Username: (asks for input which I provide then press enter)
Password: (same as username)
-- Authentication Successful --

Thanks f开发者_运维问答or any help with this. If you need more specifics please comment :)


You can do a small vbscript for its sendkeys. Lets say if the prompt comes up and it focuses on the username first, then if you can do one TAB and its on password, and you're allowed to use the RETURN key to submit your credentials, you can add this to your batch script:

CSCRIPT //NoLogo //B "C:\Folder\sendkeys.vbs"
PING 1.1.1.1 -n 1 -w 11000 >NUL

Then create a file (in this example) called sendkeys.vbs with say Notepad, and add the following lines of code:

set wshShell = WScript.CreateObject("WSCript.shell")

wscript.sleep 5000
wshShell.sendkeys "type username here"
wscript.sleep 1000
wshShell.sendkeys "{ENTER}"
wscript.sleep 3000 
wshShell.sendkeys "type password here"
wscript.sleep 1000
wshShell.sendkeys "{ENTER}"
WScript.Quit

I do this for auto-sending emails in Thunderbird via the command line.


I'm afraid, you can't do this, because telnet is an executable file, so processing of input (user name and password) is just an internal logic of this program.

This would be possible only if telnet supports user name and password as command line arguments.


But there is some tricky workaround exists. Ask your friend, a programmer, to write a simple program that

  1. Accepts user name and password as command line arguments
  2. Runs telnet.exe with redirected console input/output
  3. Tracks changes in console output (waits for user input)
  4. Simulates typing user name and password
  5. Returns the same error code that telnet do
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜