[英]Ip address to NetBIOS/FQDN name in Java/Android
given the ip address of a computer on the same network of my Android device, i have to find its NetBIOS/FQDN name ... is there any "clean" solution to accomplish this with the Android SDK and generally speaking in java ? 给定与我的Android设备位于同一网络上的计算机的IP地址,我必须找到其NetBIOS / FQDN名称...是否有任何“干净”的解决方案可通过Android SDK来实现,并且通常使用Java?
Obviously InetAddress.get*HostName does not return the NetBIOS name :) 显然,InetAddress.get * HostName不返回NetBIOS名称:)
Actually, the code provided by Tom does not work, this code works for me (with JCIFS lib.) 实际上,汤姆提供的代码不起作用,该代码对我有用(使用JCIFS lib。)
NbtAddress[] nbts = NbtAddress.getAllByAddress("IP ADDRESS AS STRING");
String netbiosname = nbts[0].getHostName();
returns NetBios device name as string if successful or throws UnknownHostException if target does not exist or has no NetBios name. 如果成功,则以字符串形式返回NetBios设备名称;如果目标不存在或没有NetBios名称,则返回UnknownHostException。
Try this... 尝试这个...
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
public class SearchNetBIOSName {
public static void main(String[] args) {
try {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://my.domain.com:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=administrator,cn=users,dc=my,dc=domain,dc=com");
env.put(Context.SECURITY_CREDENTIALS, "********");
LdapContext context = new InitialLdapContext(env, null);
String searchBase = "cn=Partitions,cn=Configuration,dc=my,dc=domain,dc=com";
String searchFilter = "(&(objectcategory=Crossref)(netbiosname=*))";
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
NamingEnumeration answers = context.search(searchBase, searchFilter, controls);
while (answers.hasMore()) {
SearchResult rs = (SearchResult) answers.next();
String netBiosName = rs.getAttributes().get("NetBIOSName").get(0).toString();
System.out.println(netBiosName);
}
context.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.