要查找LastLogonTimestamp小于特定日期或为空的计算机,可以使用以下步骤:
以下是一个示例Python脚本,用于查找LastLogonTimestamp小于特定日期或为空的计算机:
import datetime
import pytz
import ldap
def get_last_logon_timestamp(computer_dn):
try:
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
conn = ldap.initialize('ldap://your_domain_controller')
conn.set_option(ldap.OPT_REFERRALS, 0)
conn.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
conn.set_option(ldap.OPT_X_TLS, ldap.OPT_X_TLS_DEMAND)
conn.set_option(ldap.OPT_X_TLS_DEMAND, True)
conn.set_option(ldap.OPT_DEBUG_LEVEL, 255)
conn.start_tls_s()
conn.simple_bind_s('your_username', 'your_password')
result = conn.search_s(computer_dn, ldap.SCOPE_BASE, '(objectClass=*)', ['lastLogonTimestamp'])
last_logon_timestamp = result[0][1]['lastLogonTimestamp'][0].decode('utf-8')
last_logon_timestamp = last_logon_timestamp[:14] + 'Z'
last_logon_datetime = datetime.datetime.strptime(last_logon_timestamp, '%Y%m%d%H%M%S%z')
last_logon_datetime = last_logon_datetime.astimezone(pytz.timezone('Asia/Shanghai'))
return last_logon_datetime
except ldap.LDAPError as e:
print(e)
def find_computers():
computers = []
try:
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
conn = ldap.initialize('ldap://your_domain_controller')
conn.set_option(ldap.OPT_REFERRALS, 0)
conn.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
conn.set_option(ldap.OPT_X_TLS, ldap.OPT_X_TLS_DEMAND)
conn.set_option(ldap.OPT_X_TLS_DEMAND, True)
conn.set_option(ldap.OPT_DEBUG_LEVEL, 255)
conn.start_tls_s()
conn.simple_bind_s('your_username', 'your_password')
result = conn.search_s('your_base_dn', ldap.SCOPE_SUBTREE, '(objectClass=computer)', ['distinguishedName'])
for dn, _ in result:
last_logon_timestamp = get_last_logon_timestamp(dn)
if last_logon_timestamp is None or last_logon_timestamp < datetime.datetime(2022, 1, 1, tzinfo=pytz.timezone('Asia/Shanghai')):
computers.append(dn)
except ldap.LDAPError as e:
print(e)
return computers
computers = find_computers()
for computer in computers:
print(computer)
请注意,上述示例代码中的"your_domain_controller"、"your_username"、"your_password"、"your_base_dn"需要替换为实际的域控制器信息和凭据。
对于腾讯云相关产品和产品介绍链接地址,由于要求不能提及具体品牌商,建议在腾讯云官方网站上查找相关产品和文档。可以参考腾讯云的云服务器(CVM)、云数据库(CDB)、云监控(Cloud Monitor)等产品,以满足云计算领域的需求。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云