简体   繁体   中英

get LDAP server ip(s) by php

Is there any way to find out the LDAP server ip(s) by using php code? I didn't found anything related to what I want So there is nothing I try. Just reading Ldap and found nothing for get LDAP server ip by php.

You could use the following drop in function to get the LDAP servers in a given domain:

/**
 * Get an array of all the LDAP servers for a domain by querying DNS.
 *
 * @param string $domain The domain name to query.
 * @return string[]
 */
function getLdapServersForDomain($domain)
{
    $hosts = dns_get_record('_ldap._tcp.'.$domain, DNS_SRV);

    return is_array($hosts) ? array_column($hosts, 'target') : [];
}

Where $domain is the fqdn, such as mydomain.com .

That will get the LDAP server names. If you really need the IP addresses instead I could add some additional logic to it for you. This also assumes at least PHP 5.5 with the use of array_column .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM