From: Christopher A B. <ca...@tc...> - 2002-01-14 21:38:29
|
As K Reddy once put it so eloquently: > Instead, he suggested that I query DNS for the SRV > record, which looks like this: > _.gc._tcp.us-city._sites.company.com. > > It worked when I used nslookup from a DOS prompt, but > I'm not sure how to look it up in UNIX. > I tried the Net::DNS module, but I honestly couldn't > figure out how (or if) it works for looking up SRV > records. Here is the code we use to lookup the PDC for doing Active Directory updates, using Net::DNS. Call it with the domain that you're trying to update. Returns a hostname and port. Note that I "hardcode" in the LDAPS port (via getservbyname) since MS doesn't define _ldaps as a service name. Change ldaps to ldap in the getservbyname, or return $rr->port to use the port in the SRV record, if you want non-ssl LDAP. ####snip sub lookup_pdc { my ($dc) = @_; 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 { ¬e("SRV lookup failed: " . $res->errorstring); } return; } ####snip %% Christopher A. Bongaarts %% ca...@tc... %% %% Internet Services %% http://umn.edu/~cab %% %% University of Minnesota %% +1 (612) 625-1809 %% |