The are multiple ways to do this depending on whether you want the DNS name, the NetBIOS name or both.
Quick and dirty to get the DNS name is to connect to the domain controller with a search base of an empty string and searchScope of Base. Read the dnsHostname attribute. Remove everything up to and including the first period and you are left with the DNS domain of the domain controller.
If you want the DNS name and the NetBIOS name, you need to de a little more work. Connect to the domain controller with a search base of an empty string and searchScope of Base, read the configurationNamingContext and defaultNamingContext attributes. Set the value in the configurationNamingContext as the search base and the filter to (&(objectClass=crossRef)(nCName=value of defaultNamingContext)) and read the value of the nETBIOSName attribute for the short name and the dnsRoot attribute for the DNS domain name.