#!/usr/bin/python3 import collections import configparser import time import socket import ldap import ldap.sasl SASL_GSSAPI = ldap.sasl.sasl({}, 'GSSAPI') SASL_GSS_SPNEGO = ldap.sasl.sasl({}, 'GSS-SPNEGO') METH = SASL_GSSAPI with open("/etc/ipa/default.conf") as f: cfg = configparser.RawConfigParser() cfg.read_file(f) URI = cfg.get("global", "ldap_uri") assert URI.startswith("ldapi://") def profile(uri, meth): conn = ldap.initialize(uri) conn.whoami_s() # start connection start = time.perf_counter() try: conn.sasl_interactive_bind_s('', meth) return time.perf_counter() - start finally: conn.unbind() # acquire service ticket profile(URI, METH) ctr = collections.Counter() for i in range(2000): dur = profile(URI, METH) dur = round(dur * 1000) ctr.update({dur: 1}) # print(f"{dur}ms") if dur > 500: c = "O" elif dur > 20: c = "x" else: c = "." print(c, end="", flush=True) print() for dur, count in sorted(ctr.items()): print(f"{dur}ms\t{count}")