1

我一直在尝试logonHours显示,同时使用Python 3.7。当我去显示 logonHours 时,作为输出它给了我 等等。pyadmemory at 0x0000000003049708

不确定如何显示该数据。所有其他属性都正确显示。

from pyad import *
q = pyad.adsearch.ADQuery()
q.execute_query(
    attributes= ["distinguishedName", "givenName", "userWorkstations","homeDirectory", "homeDrive", "logonHours"],
    where_clause = "objectClass = '*'",
    base_dn = "OU=Graphic Design Students, DC=someplace, DC=com"
)
adoutput = []
for row in q.get_results():
    adoutput.append(row["distinguishedName"])
    adoutput.append(row["givenName"])
    adoutput.append(row["userWorkstations"])
    adoutput.append(row["homeDirectory"])
    adoutput.append(row["homeDrive"])
    adoutput.append(row["logonHours"])
adoutput = [x for x in adoutput if x != None]

print(adoutput)

我的输出看起来像:

<memory at 0x0000000003049708>
<memory at 0x00000000030497C8>
<memory at 0x0000000003049888>
<memory at 0x0000000003049948>
<memory at 0x0000000003049A08>
<memory at 0x0000000003049AC8>
4

3 回答 3

1

利用

row["logonHours"].tobytes() 

获取字节值——您将看到 ADSIEdit 为属性值显示的同样相当神秘的东西。

诀窍就是把它变成神秘的东西。在https://social.technet.microsoft.com/Forums/exchange/en-US/545552d4-8daf-4dd8-8291-6f088f35c2a4/how-is-the-logon-hours中有一个很好的解释值是如何编码的-attribute-set-in-active-directory-windows-server-2008-r2-?forum=winserverDS

于 2018-11-09T21:37:32.543 回答
0

LogonHours 是一个 COM 对象。

这是我处理 logonHours 属性的方法。在我的循环中,我检查数据类型:

import pyad.pyadutils
import win32com.client
if isinstance(v, win32com.client.CDispatch):
    value = pyad.pyadutils.convert_datetime(v)

这给了我一个可以使用的日期时间对象。希望这可以帮助某人。

于 2020-01-10T15:28:11.003 回答
0

使用@LisaJ 的答案中链接的文章,这里有一些您可以使用此属性的应用程序。希望这可以帮助某人。

#Convert the array to a list of which hours each day the account is logged in
weekList = []
for shift_1, shift_2, shift_3 in zip(*[iter(row["logonHours"].tobytes())]*3):
    weekList.append(format(shift_1, '08b') + format(shift_2, '08b') + format(shift_3, '08b'))

#Total the hours for each day
totalHours = {}
for i, (shift_1, shift_2, shift_3) in enumerate(zip(*[iter(row["logonHours"].tobytes())]*3)):
    totalHours[i] = len((format(shift_1, '08b') + format(shift_2, '08b') + format(shift_3, '08b')).replace("0", ""))
于 2020-11-05T20:04:40.667 回答