Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get hostname from IP with JCIFS

Tags:

java

jcifs

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.

like image 258
tiwiz Avatar asked Dec 08 '25 06:12

tiwiz


1 Answers

JCIFS stop supports Netbios name resolution on 1.3.14 version. You can find release notes for stopping this. https://jcifs.samba.org/

like image 185
Justin Song Avatar answered Dec 09 '25 20:12

Justin Song



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!