daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Jun 30th, 2018 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'rubygems'
  2. require 'net/ldap'
  3.  
  4. def get_ldap_response(ldap)
  5.   msg = "Response Code: #{ ldap.get_operation_result.code }, Message: #{ ldap.get_operation_result.message }"
  6.  
  7.   raise msg unless ldap.get_operation_result.code == 0
  8. end
  9.  
  10.  
  11. ldap = Net::LDAP.new  :host => # your LDAP host name or IP goes here,
  12.                       :port => # your LDAP host port goes here,
  13.                       :encryption => :simple_tls,
  14.                       :base => # the base of your AD tree goes here,
  15.                       :auth => {
  16.                         :method => :simple,
  17.                         :username => # a user w/sufficient privileges to read from AD goes here,
  18.                         :password => # the user's password goes here
  19.                       }
  20.  
  21.  
  22. search_param = # the AD account goes here
  23. result_attrs = ["sAMAccountName", "displayName", "mail"] # Whatever you want to bring back in your result set goes here
  24.  
  25. # Build filter
  26. search_filter = Net::LDAP::Filter.eq("sAMAccountName", search_param)
  27.  
  28. # Execute search
  29. ldap.search(:filter => search_filter, :attributes => result_attrs) { |item|
  30.   puts "#{item.sAMAccountName.first}: #{item.displayName.first} (#{item.mail.first})"
  31. }
  32.  
  33. get_ldap_response(ldap)
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