SHARE
TWEET

Untitled

a guest Apr 27th, 2018 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3.6
  2. # -*- coding: utf-8 -*-
  3.  
  4. import ldap3
  5. from pprint import pprint
  6.  
  7. ad_name='DC=D111TEST,DC=rdi'
  8. server_win_uri = '192.168.1.240'
  9. search_filter = "(&(objectClass=person)(sAMAccountName=*)(sn=*))"
  10. win_bind_name = "Администратор@D111TEST.rdi"
  11. win_bind_passwd = "password"
  12. attrs = ['*']
  13. def get_users_win_data(ip,search_base,search_filter,attrs,win_bind_name,win_bind_passwd):
  14.     server = ldap3.Server('ldap://{}'.format(ip))
  15.     with ldap3.Connection(server,user=win_bind_name,password=win_bind_passwd) as conn:
  16.         conn.search(search_base, search_filter, attributes=attrs)
  17.         return(conn.entries)
  18.  
  19.  
  20. data2=get_users_win_data(server_win_uri,ad_name,search_filter,attrs,win_bind_name,win_bind_passwd)
  21. pprint(data2)
  22.    
  23. [DN: CN=someuser,OU=Masters,OU=lab2,DC=D111TEST,DC=rdi - STATUS: Read - READ TIME: 2018-04-27T14:08:06.749917
  24. accountExpires: 9999-12-31 23:59:59.999999
  25. badPasswordTime: 2018-04-24 11:56:12.762737+00:00
  26. badPwdCount: 0
  27. cn: someuser
  28. codePage: 0
  29. countryCode: 0
  30. dSCorePropagationData: 1601-01-01 00:00:00+00:00
  31. departmentNumber: ou=Masters
  32. distinguishedName: CN=someuser,OU=Masters,OU=lab2,DC=D111TEST,DC=rdi
  33. givenName: someuser
  34. instanceType: 4
  35. lastLogoff: 1601-01-01 00:00:00+00:00
  36. lastLogon: 2018-04-24 11:56:18.622112+00:00
  37. lastLogonTimestamp: 2018-04-24 10:02:28.178299+00:00
  38. logonCount: 4
  39. name: someuser
  40. objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=D111TEST,DC=rdi
  41. objectClass: top
  42.              person
  43.              organizationalPerson
  44.              user
  45.              inetOrgPerson
  46. objectGUID: {409fcaa2-7f38-4323-85b8-73f3b502bdd7}
  47. objectSid: S-1-5-21-1391473009-3346311289-2259281666-1128
  48. primaryGroupID: 513
  49. pwdLastSet: 2018-04-24 12:04:53.419655+00:00
  50. sAMAccountName: someuser
  51. sAMAccountType: 805306368
  52. sn: someuser
  53. telephoneNumber: 1111
  54. uSNChanged: 127091
  55. uSNCreated: 118937
  56. userAccountControl: 544
  57. whenChanged: 2018-04-24 12:04:53+00:00
  58. whenCreated: 2018-04-24 07:14:22+00:00
  59. ,
  60.  DN: CN=b.young,OU=lab1,DC=D111TEST,DC=rdi - STATUS: Read - READ TIME: 2018-04-27T14:08:06.752707
  61. accountExpires: 9999-12-31 23:59:59.999999
  62. badPasswordTime: 1601-01-01 00:00:00+00:00
  63. badPwdCount: 0
  64. cn: b.young
  65. codePage: 0
  66. countryCode: 0
  67. dSCorePropagationData: 1601-01-01 00:00:00+00:00
  68. departmentNumber: DEV
  69. distinguishedName: CN=b.young,OU=lab1,DC=D111TEST,DC=rdi
  70. givenName: Beatrix
  71. instanceType: 4
  72. lastLogoff: 1601-01-01 00:00:00+00:00
  73. lastLogon: 1601-01-01 00:00:00+00:00
  74. logonCount: 0
  75. name: b.young
  76. objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=D111TEST,DC=rdi
  77. objectClass: top
  78.              person
  79.              organizationalPerson
  80.              user
  81.              inetOrgPerson
  82. objectGUID: {964ccd96-96c6-48bb-8540-c76168862262}
  83. objectSid: S-1-5-21-1391473009-3346311289-2259281666-1122
  84. primaryGroupID: 513
  85. pwdLastSet: 1601-01-01 00:00:00+00:00
  86. sAMAccountName: $231000-QQ3FD6G7KIUJ
  87. sAMAccountType: 805306368
  88. sn: Young
  89. telephoneNumber: 1111
  90. uSNChanged: 114806
  91. uSNCreated: 114805
  92. userAccountControl: 546
  93. whenChanged: 2018-04-23 09:49:40+00:00
  94. whenCreated: 2018-04-23 09:49:40+00:00
  95. ]
  96.    
  97. from ldap3 import Connection, Server, NTLM, ALL, ALL_ATTRIBUTES
  98.  
  99. # ...    
  100. server = ldap3.Server('ldap://{}'.format(ip), get_info=ALL)
  101. # ...
  102. attrs = ['sAMAccountName']
  103. conn.search(search_base, search_filter, attributes=attrs)
  104.    
  105. res = [e['sAMAccountName'].value for e in conn.entries]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top