繁体   English   中英

如何在Java中获取活动目录域名

[英]How get active directory domain name in java

请告诉我如何从Java获取活动目录域名?我尝试了此System.out.println(System.getenv(“ USERDOMAIN”)); 但是我只知道电脑的名字

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

我这样做是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]);

而且我得到了IP地址和computername.domainname

尝试使用

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

如果这不起作用,您可以(如James Tanner所说)尝试解析系统变量以找到所需的变量:

    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());
    }

本文开始 ,请尝试检查DomainName环境变量。

或者,从这个问题开始 ,尝试LOGONSERVER变量。

如果那行不通,我建议您直接查看您的环境变量(方向取决于您所运行的Windows版本),以找到实际包含您要查找的信息的变量,然后使用那个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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