How to determine the active directory server IP address or name

If you logon to a domain you can get the IP address of the active directory server by executing the following steps:

start > cmd > echo %LOGONSERVER%

 

You could also try to ping you’re domain:

start > cmd > ping mydomain.local

 

If you want to determine the domain controller name in C#, use:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices.AccountManagement;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
            {
                string controller = context.ConnectedServer;
                Console.WriteLine(string.Format("Domain Controller: {0}", controller));
                Console.WriteLine("Press any key to exit.");
                Console.ReadLine();
            }
        }
    }
}

Result

image