Hi Ronald, On Thursday, 31. August 2006 11:35, [EMAIL PROTECTED] wrote: > I need to connect to a ldap server (win 2k domain server) from a perl > script: > > use Net::LDAP; > my $ldapServer = "ldap://my.ldap.hostname"; > my $ad = Net::LDAP->new($ldapServer) or die "Could not connect to ldap > '$ldapServer': $@"; > > This works fine if I use a (fully qualified) hostname (as above). But > if I use the name of the windows domain instead (as in a normal window > account "ourdomain\userid") I get this error: > > IO::Socket::INET: Bad hostname 'ourdomain'
This is the expected behaviour. LDAP URIs contain the scheme (ldap://) followed by a hostname (either FQDN or relative to the current DNS domain) or an IP address. If 'ourdomain' cannot be resolved to an IP address using DNS this results in the above error message. > Funnily when my asp.net collegue uses the same connection-string/method > from within asp.net it works fine. This looks like an extension from MS. I do not consider those non-standard extensions funny. > > Now the question is, how can I connect to a ldap server when only the > domain-name (from the userid) is known? Find the domain controllers for the domain. They are offered in DNS. It should be possible using code like the following: ## find PDC of an AD domain with LDAPS port ## # Synopsis: ($ip, $oport) = lookup_pdc($domain) sub lookup_pdc($) { my $dc = shift; my $res = new Net::DNS::Resolver; my $query = $res->send("_ldap._tcp.pdc._msdcs.$dc", "SRV"); if ($query) { foreach $rr ($query->answer) { next unless ($rr->type eq 'SRV'); # return first found; # find ldaps port from services file since # there's no _ldaps SRV record return($rr->target, scalar(getservbyname('ldaps', 'tcp'))); } } else { die "SRV lookup failed: " . $res->errorstring; } return; } Please note: I copied this from a posting to this(?) ML years ago. I cannot tell whether it will work or not. Regards Peter -- Peter Marschall [EMAIL PROTECTED]