[prev in list] [next in list] [prev in thread] [next in thread]
List: perl-ldap-dev
Subject: RE: Is it possible to query DNS for a SRV record in perl?
From: K Reddy <kreddy4 () yahoo ! com>
Date: 2002-01-30 17:43:18
[Download RAW message or body]
Thank you so much, Christopher. I finally got the
script to work! It was so exciting.
kary
FROM: Christopher A BongaartsDATE: 01/14/2002
13:38:24SUBJECT:
RE: Is it possible to query DNS for a SRV record in
perl?
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 %% <EMAIL: PROTECTED>
%%
%% Internet Services %% http://umn.edu/~cab
%%
%% University of Minnesota %% +1 (612) 625-1809
%%
__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions!
http://auctions.yahoo.com
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic