[英]How to translate a domain name to LDAP DC when working in a Active Directory forest in 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());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.