Created
September 19, 2018 21:40
-
-
Save atucom/050778b08b5b87076127eee92d29529e to your computer and use it in GitHub Desktop.
Check if port responds to a SSL handshake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import ssl | |
def is_SSL_enabled(ip, port): | |
""" | |
Attempts a SSL connection to the specified ip:port | |
Note: Does not handle STARTTLS yet | |
returns True if handshake was successful, false if not | |
""" | |
context = ssl.create_default_context() | |
try: | |
with socket.create_connection((ip, port)) as sock: | |
with context.wrap_socket(sock, server_hostname=ip) as ssock: | |
ssock.version() | |
return True | |
except ssl.SSLError: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment