简体   繁体   中英

How get active directory domain name in java

Tell me please How can i get active directory domain name from java I tried this System.out.println(System.getenv("USERDOMAIN")); but I only get the name of the computer

======================

I did so InetAddress inet = InetAddress.getLocalHost(); InetAddress[] ips = InetAddress.getAllByName(inet.getCanonicalHostName()); usernameId.setText(System.getProperty("user.name")); 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]); computernameId.setText(str[0]); InetAddress inet = InetAddress.getLocalHost(); InetAddress[] ips = InetAddress.getAllByName(inet.getCanonicalHostName()); usernameId.setText(System.getProperty("user.name")); 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]); computernameId.setText(str[0]);

And i get ip address and computername.domainname

Try using

System.out.println(System.getenv("USERDNSDOMAIN"));

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>)iter.next();
        System.out.println(pair.getKey() + " = " + pair.getValue());
    }

From this article , try checking the DomainName environment variable.

Or, from this question , try the LOGONSERVER variable.

If that doesn't work, I'd recommend taking a look at your environment variables directly (directions vary depending on which version of Windows you're running) to find the one that actually contains the information you're looking for, then use that one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM