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") 
  • try socket.inetAddress.hostName - Komdosh
  • I tried it, it also returns the ip address, but this is described in the documentation, but why canonicalHostName does not work, I don’t understand - Kitsune
  • and at that computer in general the name is exposed? - Komdosh
  • Yes, I tried several at once. Yes, and other applications show the name in some way. I understand this name netbios or something like that, it is limited to 15 characters. But I can not get any name. - Kitsune
  • here is the answer at stackoverflow.com/questions/34842698/… - Komdosh

0