RE: [PHP] Domain Controller Discovery in PHP
| From: | Jason | Date: | Tue, 28 Sep 2010 08:03:35 +0000 |
| Subject: | RE: [PHP] Domain Controller Discovery in PHP | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-308339@lists.php.net to get a copy of this message | ||
-----Original Message-----
From: Robert Cummings [mailto:robert@interjinn.com]
Sent: 27 September 2010 19:38
To: Jason
Cc: 'PHP General'
Subject: Re: [PHP] Domain Controller Discovery in PHP
On 10-09-27 11:26 AM, Jason wrote:
> Hi Rob,
>
> I believe you should be able to do this with nothing more than DNS (this is how Windows clients
> do it).
>
> Once you have the DNS domain of the machine you're on
> (_SERVER["USERDNSDOMAIN"]), query for SRV records called the following:
>
> Name: _ldap._tcp.dc._msdcs.<machine domain name>
>
> That should return one or more records in the answer, each one will be the FQDN of a domain
> controller.
>
> Additional info from the horses mouth:
> http://support.microsoft.com/kb/247811
Hi Jason,
Thanks for the info. I don't actually have that server field (maybe
because the article is for windows 2000), but maybe I can use your info
to get to the next step anyways.
Cheers,
Rob.
--
Hi Rob,
I've checked a couple of windows machines (which I admit I had assumed you were running php on)
and the ENV variable "USERDNSDOMAIN" is definitely what you need. If your php is running
on linux, you'll need to find out the target windows domain some other way (user input/config
file maybe?).
The article is a Win2k based one - there is a link to the XP one in the top-right corner. However I
read both and things haven't changed from a DNS point of view.
Here's a code snippet for you (run on my network from a windows workstation)...
<?php
# assume $_SERVER["USERDNSDOMAIN"] is equal to "xxx.local".
print_r(
dns_get_record("_ldap._tcp.dc._msdcs.".$_SERVER["USERDNSDOMAIN"],DNS_SRV) );
?>
And the output (edited for obvious reasons):
Array
(
[0] => Array
(
[host] => _ldap._tcp.dc._msdcs.xxx.local
[type] => SRV
[pri] => 0
[weight] => 100
[port] => 389
[target] => dc2.xxx.local
[class] => IN
[ttl] => 545
)
[1] => Array
(
[host] => _ldap._tcp.dc._msdcs.xxx.local
[type] => SRV
[pri] => 0
[weight] => 100
[port] => 389
[target] => dc1.xxx.local
[class] => IN
[ttl] => 545
)
)
HTH
J