如何打开 cmd 窗口并使用批处理文件传递硬编码值?

发布于 2024-11-15 12:13:05 字数 495 浏览 4 评论 0原文

我找到了许多接近我想要的解决方案,但并不完全是我想要的,而且我自己也没有运气。

我正在尝试创建一个可用于自动进行防火墙身份验证的脚本。我现在正在手动执行此操作,方法是打开 cmd 窗口并尝试远程登录到防火墙后面的设备/电脑。短暂暂停后,系统提示我输入用户名和密码。

有没有办法编写一个批处理文件来打开一个cmd窗口并提供这两个值?

目前情况如下:

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 --

感谢您对此的任何帮助。如果您需要更多具体信息,请评论:)

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 for any help with this. If you need more specifics please comment :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倒数 2024-11-22 12:13:05

您可以为其发送键编写一个小的 vbscript。假设出现提示并且它首先关注用户名,那么如果您可以执行一个 TAB 及其密码,并且允许您使用 RETURN 键提交您的凭据,您可以将其添加到批处理脚本中:

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

然后使用记事本创建一个名为 sendkeys.vbs 的文件(在本例中),并添加以下代码行:

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

我这样做是为了通过命令行在 Thunderbird 中自动发送电子邮件。

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.

万人眼中万个我 2024-11-22 12:13:05

恐怕,你不能这样做,因为telnet是一个可执行文件,所以输入(用户名和密码)的处理只是这个程序的内部逻辑。

仅当 telnet 支持用户名和密码作为命令行参数时,这才可能实现。


但存在一些棘手的解决方法。请您的程序员朋友编写一个简单的程序,该程序

  1. 接受用户名和密码作为命令行参数使用
  2. 重定向的控制台输入/输出运行 telnet.exe
  3. 跟踪控制台输出中的更改(等待用户输入)
  4. 模拟键入用户名和密码
  5. 返回与 telnet 相同的错误代码

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文