use Net::LDAP; my $server = "192.168.0.20"; my $port = "389"; my $connection = Net::LDAP->new($server, port => $port) or die "Unable to connect to $server:", @$, "\n"; $connection->bind() or die "could not bind: $@\n"; print "\n\nConnected to LDAP\n\n"; my @attrs = ['username', 'plan', 'ipaddress']; open MACS, "macs.txt" or die "Couldn't open the file or die: $!\n"; @macs = ; close MACS; print "Opened the Macs file\n"; my $count=0; foreach my $mac (@macs) { $count++; print "Processing: $count\n"; ldapsearch($mac); } sub ldapsearch { my $mac = shift; print "$mac\n"; my $searchobj = $connection->search( base => 'o=ldap, filter => "cn=$mac", attrs => @attrs, callback => \&callback, ); $searchobj->code && die $searchobj->error; } sub callback { my ($searchobj, $entry) = shift @_; $entry = $searchobj->shift_entry; if ($entry) { print $entry->dn, "\n"; print $entry->get_value('plan'); print $entry->get_value('ipaddress'); print $entry->get_value('username'); } }