#!/usr/bin/env python2.7 # encoding: utf-8 from __future__ import absolute_import from ldap3 import ( ALL, Connection, SASL, Server, ) def gssapi_auth_supported(server): s = Server(server, get_info=ALL) c = Connection(s) c.open() return 'GSSAPI' in s.info.supported_sasl_mechanisms def bind_gssapi(server): s = Server(server, use_ssl=False) c = Connection(s, authentication=SASL, sasl_mechanism='GSSAPI') c.bind() return c def main(): import sys import os MYNAME = os.path.basename(__file__) if len(sys.argv) != 2: raise ValueError("Usage: %s domain_controller" % MYNAME) conn = bind_gssapi(sys.argv[1]) if __name__ == '__main__': main()