Created
November 6, 2009 00:47
-
-
Save eight/227565 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8-*- | |
# python-ldapを使ってActiveDirectoryで認証してみる | |
# http://python-ldap.sourceforge.net/ | |
def ADAuth(username,password,host,port=389): | |
"""ActiveDirectoryのドメイコントローラにユーザ名とパスワードでbindしてみる。 | |
bindできれば認証OK。認証NGなら例外が起きる。 | |
""" | |
import ldap | |
url = "ldap://%s:%d" % (host,port) | |
l = ldap.initialize(url) | |
l.simple_bind_s(username,password) | |
l.unbind_s() | |
if __name__=='__main__': | |
if len(sys.argv)<3: | |
print "Usage: %s username password" % (sys.argv[0]) | |
else: | |
try: | |
userid = sys.argv[1] | |
password = sys.argv[2] | |
ADAuth(userid,password,"adserver.example.com") | |
print "OK" | |
except: | |
print "NG" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment