(a)
Get SSL Cert CN
Get SSL Cert CN
Get SSL Cert CN
def getcert(a):
    """Get SSL Cert CN"""
    refPorts = open('config/ports.txt', 'r').readlines()
    for port in refPorts:
        # Make sure we don't have any extra characters like \n or \r
        port = port.rstrip()
        try:
            # time to connect!
            cert = ssl.get_server_certificate((a, port))
        except Exception, e:
            # If it can't connect go to the next iteration so we don't waste time
            continue
        try:
            # use openssl to pull cert information
            c = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
            subj = c.get_subject()
            comp = subj.get_components()
            for data in comp:
                if 'CN' in data:
                    out[a] = a,data[1]
                elif 'CN' not in data:
                    continue
                else:
                    continue
        except Exception,e:
            # if openssl fails to get information, return nothing
            continue
def getcert ( a ) : refPorts = open ( 'config/ports.txt' , 'r' ) . readlines ( ) for port in refPorts : # Make sure we don't have any extra characters like \n or \r port = port . rstrip ( ) try : # time to connect! cert = ssl . get_server_certificate ( ( a , port ) ) except Exception , e : # If it can't connect go to the next iteration so we don't waste time continue try : # use openssl to pull cert information c = OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM , cert ) subj = c . get_subject ( ) comp = subj . get_components ( ) for data in comp : if 'CN' in data : out [ a ] = a , data [ 1 ] elif 'CN' not in data : continue else : continue except Exception , e : # if openssl fails to get information, return nothing continue