try { val socket = Socket() val connection = socket.connect(InetSocketAddress(ipAddress, 445), 50) val hostName = socket.inetAddress.canonicalHostName socket.close() } catch (e: IOException) {}
socket.inetAddress.canonicalHostName should return the computer name, but I still get the IP address. What are the solutions to this problem? I do not really understand the networks ...
Changed: Working version, using outdated JCIFS 1.3.17 library
val nbtAddr = NbtAddress.getAllByAddress(ipAddress) val hostName = nbtAddr[0].hostName Log.v(DEBUG_TAG, "Host name - $hostName")
Solution : Works with the new jcifs-ng library
val cifsContext = BaseContext(PropertyConfiguration(System.getProperties())).withGuestCrendentials() val hostName = cifsContext.nameServiceClient.getNbtAllByAddress(ipAddress)[0].name.name Log.v(DEBUG_TAG, "Host name - $hostName, IP - $ipAddress")