Skip to content

Instantly share code, notes, and snippets.

@morteza-mori
Last active July 29, 2018 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morteza-mori/1408bddc3aa05fd38312ea14e4a85dcb to your computer and use it in GitHub Desktop.
Save morteza-mori/1408bddc3aa05fd38312ea14e4a85dcb to your computer and use it in GitHub Desktop.
ldap test python
import ldap, sys
LDAP_SERVER = 'ldaps://grep01.test.test.ir'
LDAP_BASE = 'ou=Special Users,dc=gandou,dc=test,dc=test,dc=ir'
BIND_USER = 'uid=ibsngproxy,ou=Users,dc=test,dc=test,dc=ir'
BIND_PASSWORD = 'halohalohalo'
ldap.set_option(ldap.OPT_DEBUG_LEVEL, 4095)
try:
l = ldap.initialize(LDAP_SERVER)
except ldap.LDAPError, e:
sys.stderr.write("Fatal Error\n")
raise
try:
l.protocol_version = ldap.VERSION3
l.simple_bind_s(BIND_USER, BIND_PASSWORD)
result = l.search_s(LDAP_BASE, ldap.SCOPE_SUBTREE)
print result
print "OK"
l.unbind()
except Exception, error:
print error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment