code_junkie

How to get domain controller IP Adress

Nov 13th, 2011
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. // get root of the directory data tree on a directory server
  2. DirectoryEntry dirEntry = new DirectoryEntry("LDAP://rootDSE");
  3. // get the hostname of the directory server of your root (I'm assuming that's what you want)
  4. string dnsHostname = dirEntry.Properties["dnsHostname"].Value.ToString();
  5. IPAddress[] ipAddresses = Dns.GetHostAddresses(dnsHostname);
  6.  
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using System.Net;
  11. using System.Net.Sockets;
  12. using System.DirectoryServices.AccountManagement;
  13. using System.DirectoryServices.ActiveDirectory;
  14. public doIt()
  15. {
  16. DirectoryContext mycontext = new=DirectoryContext(DirectoryContextType.Domain,"project.local");
  17. DomainController dc = DomainController.FindOne(mycontext);
  18. IPAddress DCIPAdress = IPAddress.Parse(dc.IPAddress);
  19. }
Add Comment
Please, Sign In to add comment