ldap匿名訪問測試腳本


#!/usr/bin/env python
# encoding: utf-8
# http://ldap3.readthedocs.io/tutorial.html#accessing-an-ldap-server
import ldap3
from fileutils import FileUtils
import os
from ldap3 import Connection

def verify(host):
        try:
            print host
            server = ldap3.Server(host, get_info=ldap3.ALL, connect_timeout=30)
            conn = ldap3.Connection(server, auto_bind=True)
            #print server 
            if len(server.info.naming_contexts) > 0:
                for _ in server.info.naming_contexts:
                    if conn.search(_, '(objectClass=inetOrgPerson)'):
                        naming_contexts = _.encode('utf8')
                        #print naming_contexts
                        print host + ': ' + naming_contexts

        except Exception, e:
            pass
            #print e

if __name__ == '__main__':
    for host in FileUtils.getLines('ldap.lst'):
        verify(host)

測試截圖:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM