user1711993
user1711993

Reputation: 271

How to know that Active Directory exists with only ip address?

How to know that AD exists?

I have only ip address. I tried to use those methods:

if(DirectoryEntry.Exists("LDAP://192.168.1.1"))

also

DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://192.168.1.1")

but it didn't help. I use LdapConnection right now, but I have a problem

LdapConnection connection = new LdapConnection(new LdapDirectoryIdentifier("192.168.1.1"));
                        connection.AuthType = AuthType.Basic;
                        NetworkCredential credential =
        new NetworkCredential("a", '1");

                        connection.Credential = credential;

                        connection.Timeout = new TimeSpan(1000);
                        connection.Bind();

I'm getting 81 code and The LDAP unavailable.

Does somebody know is possible just to know is ip is correct and AD exists?

P.S. I use .NET 2

Upvotes: 0

Views: 1578

Answers (2)

Rainer Schaack
Rainer Schaack

Reputation: 1618

You can try this (works with .NET 2.0 and does not need credentials):

...
using System.DirectoryServices.Protocols;
...

string server = "192.168.1.1";

using (LdapConnection ldapConnection = new LdapConnection(server))
{
    ldapConnection.AuthType = AuthType.Anonymous;

    SearchRequest request = new SearchRequest(null, "(objectclass=*)",
          SearchScope.Base, "defaultNamingContext");

    SearchResponse result = (SearchResponse)ldapConnection.SendRequest(request);

    if (result.Entries.Count == 1)
    {
        Console.WriteLine(result.Entries[0].Attributes["defaultNamingContext"][0]);
    }
}

It binds anonymously to the AD domain controller and retrieves the rootDSE entry. It displays the DN of the AD domain.

You can also query another attributes, see https://msdn.microsoft.com/en-us/library/ms684291(v=vs.85).aspx

Upvotes: 1

jwilleke
jwilleke

Reputation: 10986

AD can only be set to run on port 389 and/or 636. So if the port is open, it is a pretty good chance that LDAP is present.

Know if it is AD or not, would, typically, require you to have a valid LDAP account to BIND to the LDAP service.

You can perform a LDAP query against the LDAP service and probably learn the VendorName.

Upvotes: 1

Related Questions