4

i am working on one module to scan local network and Ip, Mac, Hostname and other details of other devices connected through the same network.

i am unable to get Host PC name from InetAddress class in android. Please check my below code:

String IpAddr = "192.168.1.52";

try {
      InetAddress inet = InetAddress.getByName(IpAddr);

      String address = inet.getHostAddress();
      String hostname = inet.getHostName();
      String canonicalhostname = inet.getCanonicalHostName();

      Log.w("Host Ip: ", IpAddr);
      Log.w("Host Address: ", address);
      Log.w("Host Name: ", hostname);
      Log.w("Canonical Host Name: ", canonicalhostname);
} catch (UnknownHostException e) {
      e.printStackTrace();
}

And output is:

Host Ip: 192.168.1.52
Host Address: 192.168.1.52
Host Name: 192.168.1.52
Canonical Host Name : 192.168.1.52

i also tried google but not getting exect output.

Its not providing host computers name and always returning IP address instead.

i am also trying to find device type ( Computer / Mobile / Laptop / Printer etc.. )

Please help guys..

Rl.Android
  • 41
  • 6

0 Answers0