2012-11-16 1 views
4

내 스크립트는 다음과 같다 :python-ldap을 사용하여 활성 디렉토리의 내용을 읽는 방법은 무엇입니까?

import ldap, sys 
server = 'ldap://my_server' 
l = ldap.initialize(server) 
dn="[email protected]" 
pw = "password" 
l.simple_bind_s(dn,pw) 
ldap.set_option(ldap.OPT_REFERRALS,0) 
print "valid" 

나는 창문에 파이썬 2.7을 사용하고 있습니다.

활성 디렉토리의 내용을 읽거나 가져올 수있는 방법이 있습니까?

답변

0

당신은 정말 (I 문제에 대한 문서를 발견했다) http://www.python-ldap.org/docs.shtml

You have a connection in your variable l, then you can do this. 

l.con_search_s('dc=your,dc=base,dc=dit', ldap.SCOPE_SUBTREE, 'uid=*', ['uid', 'uidnumber']) 

The above code, goint to search in to all the uid's entrys, for if entry, is going to get the uid and the uidnumbre attributes. 
4

당신은 또한 win32com.client를 사용하여 꽤 많은 작업을 수행 할 수 있습니다 파이썬 - LDAP의 문서를 읽을 필요합니다. 예를 들어 사용자 이름이 ADS_NAME_TYPE_NT4이고 형식이 지정된 이름 (doman\jonjoe)을 알면 사용자 이메일을 해결해야합니다. 당신이 ADS_NAME_TYPE_1779 형식 (CN=Jeff Smith,CN=users,DC=Fabrikam,DC=com)로 변환하는 데 필요한 모든의

첫째 :

name_resolver = win32com.client.Dispatch(dispatch='NameTranslate') 
name_resolver.Set(3, 'domain\\jonjoe') 
ldap_query = 'LDAP://{}'.format(name_resolver.Get(1)) 

당신이 단순히 GetObject()를 호출 할 수 있습니다 일단 :

ldap = win32com.client.GetObject(ldap_query) 
print(ldap.Get('mail')) 
파이썬 3.2.5로 테스트

+0

또한이 라이브러리는 다른 보안 주체의 도메인을 해결할 수 있습니까? 숲은 일방 통행으로 연결되어 있습니까? –

+0

@AndrzejBobak 기본적으로 WinAPI를 랩핑하므로 WinAPI에서 작성할 수 있다면'win32 * '파이썬 라이브러리를 사용하여 다시 작성할 수 있습니다. – Vyktor

관련 문제