Skip to content

Instantly share code, notes, and snippets.

@kfsone
Created July 8, 2021 07:10
Show Gist options
  • Save kfsone/af3ebeed0c5597c823270243420a17a0 to your computer and use it in GitHub Desktop.
Save kfsone/af3ebeed0c5597c823270243420a17a0 to your computer and use it in GitHub Desktop.
tls12_check.ps1
# Copyright (C) Oliver 'kfsone' Smith ([email protected], https://www.kfs.org/oliver) 2021
#
# Trivial powershell script to test whether a given host is reachable and supports TLS 1.2.
Param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true, HelpMessage="Specify the dns name or ip address of the imap/tls server")]
[String] $Server,
[Parameter(HelpMessage="Specify the port number to contact, default 143")]
[Int] $Port = 143
)
$has_tls12 = $false
$client = New-Object Net.Sockets.TcpClient
$client.Connect($Server, $Port)
$session = New-Object Net.Security.SslStream $client.GetStream(), $true, ([System.Net.Security.RemoteCertificateValidationCallback]{ $true })
$session.WriteTimeout = 10000
$session.ReadTimeout = 10000
try {
$session.AuthenticateAsClient($Server, $null, "tls12", $false)
$has_tls12 = $true
} catch {
$has_tls12
}
$session.Dispose()
$client.Dispose()
echo "host: $Server"
echo "port: $port"
echo "tls1.2: $has_tls12"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment