windows 连接后如何终止 OpenSSL s_client

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25760596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:42:37  来源:igfitidea点击:

How to terminate OpenSSL s_client after connection

windowsbatch-fileopenssl

提问by KenD

(Reviewers: I also know this is straying into SuperUser territory, but if the previous question snuck through ... :) )

(评论者:我也知道这是进入超级用户领域,但如果前一个问题偷偷通过...... :))

This is very similar to this question, but in an Windows (7/8/Server 2008/2012) environment: I'm using the Windows port of OpenSSL.

这与此问题非常相似,但在 Windows (7/8/Server 2008/2012) 环境中:我使用的是 OpenSSL 的 Windows 端口。

I'm running

我在跑

openssl s_client -connect 192.168.0.1:443

openssl s_client -connect 192.168.0.1:443

from a command prompt, in order to show certificate information. However, openssl waits for user input afterwards; I can Ctrl+Cto "break" the output, or every just type a few characters and hit return, but I need to automate this - all I'm really interested in is the certificate information.

从命令提示符,以显示证书信息。但是,openssl 之后会等待用户输入;我可以Ctrl+C来“中断”输出,或者每次只输入几个字符并按回车键,但我需要自动执行此操作 - 我真正感兴趣的是证书信息。

As per the previous question, I need some way to terminate/close the connection. However, I've tried piping in input files, echoing/typeing input into the mix, and nothing seems to simulate a real user. Can anyone show me how to force openssl to exit after connecting?

根据上一个问题,我需要某种方式来终止/关闭连接。不过,我已经试过管道输入文件中,echo荷兰国际集团/type荷兰国际集团投入进来,但是没有一样能模拟真实用户。谁能告诉我如何在连接后强制 openssl 退出?

回答by Degenerate DevOps

You can achieve the desired effect by using a pipe to pass in the character "Q". This makes for a great one-liner for a script:

可以通过使用管道传入字符“Q”来达到想要的效果。这为脚本提供了一个很好的单行:

echo "Q" | openssl s_client -connect host:port

If you are using a sufficiently new version of BASH, you can also use the triple less-than redirect instead of piping (some times a pipe isn't usable since it operates on stdin/stdout):

如果您使用的是足够新版本的 BASH,您还可以使用三重小于重定向而不是管道(有时管道不可用,因为它在 stdin/stdout 上运行):

openssl s_client -connect host:port <<< "Q"

回答by JSAnderson

Entering the letter 'Q' at the beginning of a blank line will end an active connection. I've seen s_client get into states where this does not do anything, but this is the documented way to quit a session.

在空行的开头输入字母“Q”将结束活动连接。我已经看到 s_client 进入了不做任何事情的状态,但这是退出会话的记录方式。

If you want to do this in batch mode, just create a text file with the letter 'Q' followed by a carriage return and direct it into the end of the command like so:

如果要在批处理模式下执行此操作,只需创建一个带有字母“Q”后跟回车符的文本文件,并将其定向到命令的末尾,如下所示:

openssl s_client -connect host:port < Q.txt

I tried this and it works.

我试过这个,它有效。