Here is a basic Python script to query Active Directory using the “ldap3” library. Useful script code for authentication.
import ldap3
server = ldap3.Server("ldap://hostname:port/")
conn = ldap3.Connection(server, "CN=username,DC=domain,DC=com", "password")
conn.bind()
query = "(&(objectCategory=person)(objectClass=user)(cn=*))"
conn.search("DC=domain,DC=com", query, attributes=["cn", "mail", "memberOf"])
result = conn.response
for item in result:
print(item["attributes"])
conn.unbind()
Replace the placeholders with the appropriate values for your Active Directory:
The “attributes” list in the conn.search()
call can be modified to retrieve other properties of the users in the directory.
Here is a simple Python script to monitor network traffic. import psutil def monitor_network(): #…
Here's a basic example of web scraping in Python using the requests and BeautifulSoup libraries:…
Here's an example of how you can use Python to SSH into a remote server…
Here's an example of a Python class that represents a rectangle: class Rectangle: def __init__(self,…
Here is a simple Python script that interacts with Active Directory (AD) using the pyad…
Here's a Python script to monitor disk usage on a system and send an email…