def masscan_x509(output):
 certificate = output.decode('base64')
 newout = []
 for (hashtype, hashname) in [('md5', 'MD5:'), ('sha1', 'SHA-1:')]:
  hashvalue = hashlib.new(hashtype, cert).hexdigest()
  newout.append(('%-7s%s\n' % (hashname, ' '.join((hashvalue[i:(i + 4)] for i in xrange(0, len(hashvalue), 4))))))
 b64cert = certificate.encode('base64')
 newout.append('-----BEGIN CERTIFICATE-----\n')
 newout.extend((('%s\n' % b64cert[i:(i + 64)]) for i in xrange(0, len(b64cert), 64)))
 newout.append('-----END CERTIFICATE-----\n')
 return ''.join(newout)

def masscan_x509 ( output ) : certificate = output . decode ( 'base64' ) newout = [ ] for ( hashtype , hashname ) in [ ( 'md5' , 'MD5:' ) , ( 'sha1' , 'SHA-1:' ) ] : hashvalue = hashlib . new ( hashtype , cert ) . hexdigest ( ) newout . append ( ( '%-7s%s\n' % ( hashname , ' ' . join ( ( hashvalue [ i : ( i + 4 ) ] for i in xrange ( 0 , len ( hashvalue ) , 4 ) ) ) ) ) ) b64cert = certificate . encode ( 'base64' ) newout . append ( '-----BEGIN CERTIFICATE-----\n' ) newout . extend ( ( ( '%s\n' % b64cert [ i : ( i + 64 ) ] ) for i in xrange ( 0 , len ( b64cert ) , 64 ) ) ) newout . append ( '-----END CERTIFICATE-----\n' ) return '' . join ( newout )
produces an output similar to nmap script ssl-cert from masscan x509 "service" tag .