Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: ldapsearch in perl

by ravi6289 (Initiate)
on Jan 08, 2013 at 04:36 UTC ( [id://1012156]=note: print w/replies, xml ) Need Help??


in reply to ldapsearch in perl

Hello Jose , You need to bind to the ldap server from there on , and use the count method to get the number of entries . Try including the below piece of code inside your subroutine,changing the $ldapserver to point to each of your hosts . The filter filter => "(objectClass=*)" , will get all of the entries Hope this helps !!!

#!/usr/bin/perl use Net::LDAP; my $ldapserver = "<Server Name>"; my $ldapbase = "ou=people,ou=Urania,ou=Eng,dc=example,dc=com"; my $ldap = Net::LDAP->new( $ldapserver ) or die "$@"; my $mesg = $ldap->bind("cn=user>,ou=people,ou=Urania,ou=Eng,dc=example +,dc=com", password=>'<user>'); $mesg = $ldap->search( base => $ldapbase, filter => "(objectClass=*)") +; my @entries = $mesg->count; print "@entries\n"; $mesg = $ldap->unbind;

Replies are listed 'Best First'.
Re^2: ldapsearch in perl
by jose_m (Acolyte) on Jan 08, 2013 at 15:04 UTC

    thanks Ravi. that seemed to help, but the error has changed, i am not getting connection refused.

    Connection refused at ldap_process.pl line 15, <DATA> line 225

      ok folks so i decided to dump the module. all i needed was to make sure that i can bind so i settled for this: hope it helps someone:

      use IO::Socket; use Socket; my $port='3000'; $socket = new IO::Socket::INET->new(PeerAddr => $ip, PeerPort => $port, Proto => 'tcp', Timeout => 2, ) or print "could not create bind to $_. port $port: $@\n" and $e +xit_status=2 ; close($socket);

      you have to use gethostbyname to resolve the ip address for the given array of hosts. any questions, just ask.. thanks -jose.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1012156]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found