我使用以下代码连接到主机:
protected bool OpenSocket(string hostIPAddress, int hostIPPort)
{
try
{
if ((this._tcpSocket != null) && (this._tcpSocket.Connected == true))
return (true);
}
catch { }
// Reset variables
this._isSocketOpen = false;
this._isSSLOpen = false;
string ipAddress = this.GetHostIPAddress(hostIPAddress);
this._tcpSocket = new TcpClient(ipAddress, hostIPPort);
this._tcpipConnectionStream = this._tcpSocket.GetStream();
this._isSocketOpen = true;
return true;
}
连接主机时有没有办法确定SSL连接类型(即SSL2,SSL3,TL1.2)?我研究过这样的事情:
SslStream sslStream = new SslStream(this._tcpSocket.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
sslStream.AuthenticateAsClient(hostIPAddress);
但是我认为那将是设置SSL协议不是它,而不是获取它?我很失落。
答案 0 :(得分:0)
您可以通过查询SslProtocol
类型的SslStream
属性来检查连接类型。
SslStream sslStream = new SslStream(this._tcpSocket.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
sslStream.AuthenticateAsClient(hostIPAddress);
Console.WriteLine(sslStream.SslProtocol);
此属性将返回Enumeration的值 SslProtocols
有关此媒体资源的详情,请参阅MSDN