Reputation: 327
I'm trying to understand how to get the name of a computer on my LAN given the IP address with JCIFS but I can't get anything but its IP.
The code I'm using is
InetAddress addr = NbtAddress.getByName( ip ).getInetAddress();
String test = UniAddress.getByName(ip).getHostName();
System.out.println("IP: " + ip + " - addr: " + addr.getHostName() + " - test: " + test);
And the result I'm getting is
IP: 10.1.2.115 - addr: 10.1.2.115 - test: 10.1.2.115
If instead I replace the getHostAddress()
with toString()
what I get is
IP: 10.1.2.115 - addr: 10.1.2.115 - test: 0.0.0.0<00>/10.1.2.115
Where am I wrong here?
I'm testing the lib from a Mac with IP 10.1.2.117
, while the target is an Android device.
Upvotes: 3
Views: 3077
Reputation: 11
/*
Jcifs 1.3 no longer calls NbtAddress#checkData() in
NbtAddress#getHostName, so you need to actively call
NbtAddress#getNodeType() or NbtAddress#isGroupAddress() before acquiring hostName.
*/
UniAddress address= UniAddress.getByName(currentIp,
true);
Object o = address.getAddress();
if (o instanceof NbtAddress) {
NbtAddress nbtAddress = (NbtAddress) o;
// jcifs 1.3 need call this method for request netbios name.
nbtAddress.getNodeType();
}
ipScan.domain = address.getHostName();
Upvotes: 1
Reputation: 181
JCIFS stop supports Netbios name resolution on 1.3.14 version. You can find release notes for stopping this. https://jcifs.samba.org/
Upvotes: 2
Reputation: 9
A bit late, but I had the same problem with jcifs 1.3.17. I reverted to 1.2.25 and it now works.
Upvotes: 0
Reputation: 21499
Can you use the standard java api instead? If so try the following
InetAddress addr = InetAddress.getByName("127.0.0.1");
String host = addr.getHostName();
Upvotes: -2