Coveraver Coveraver - 1 year ago 111
Java Question

How get active directory domain name in java

Tell me please
How can i get active directory domain name from java
I tried this
but I only get the name of the computer


I did so

InetAddress inet = InetAddress.getLocalHost();
InetAddress[] ips = InetAddress.getAllByName(inet.getCanonicalHostName());
if (ips != null) {
for (int i = 0; i < ips.length; i++) {
String[] str = ips[i].toString().split("/");
if (!(str[1].startsWith("169") || str[1].contains(":")))
System.out.println("Computer name: " + str[0] + "\nIp address: " + str[1]);

And i get ip address and computername.domainname

Answer Source

Try using


If that does not work, you can (as James Tanner said) try parsing through your system variables to find the one you want:

    Map<String, String> envMap = System.getenv();

    Iterator iter = envMap.entrySet().iterator();

    while (iter.hasNext()) {
        Map.Entry<String, String> pair = (Map.Entry<String, String>);
        System.out.println(pair.getKey() + " = " + pair.getValue());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download