python中的LDAP查询 [英] LDAP query in python

查看:370
本文介绍了python中的LDAP查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在ldap中执行以下查询

I want to execute the following query in the ldap

ldapsearch -h hostname -b dc=ernet,dc=in -x "(&(uid=w2lame)(objectClass=posixAccount))" gidnumber
ldapsearch -h hostname -b dc=ernet,dc=in -x "(&(gidNumber=1234)(objectClass=posixGroup))" cn

并使用由此获得的变量.我该怎么办?

And use the variables thus obtained. How can I do that?

推荐答案

您可能想要我们"ldap" 模块.代码如下所示:

You probably want to us the "ldap" module. Code would look something like:

    import ldap
    l = ldap.initialize('ldap://ldapserver')
    username = "uid=%s,ou=People,dc=mydotcom,dc=com" % username
    password = "my password"
    try:
      l.protocol_version = ldap.VERSION3
      l.simple_bind_s(username, password)
      valid = True
    except Exception, error:
      print error

这篇关于python中的LDAP查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆