2

I want to list all the devices connected to my network, I done like this

InetAddress i = InetAddress.getLocalHost();
byte[] ip1 = i.getAddress(); 
for (int b = 0; b <255;b++) { 
    ip1[3] = (byte)b;
    InetAddress address = InetAddress.getByAddress(ip1); 
    if (address.isReachable(3000)) {
        System.out.println("\tIP :"+address.getHostAddress());
    } else if (!address.getHostAddress().equals(address.getHostName())) { 
        System.out.println("\tIP :"+address.getHostAddress());
    } else {
    }
}

It prints all the connected devices but how to I identify which are wired connection and which are wireless, among them

André Stannek
  • 7,443
  • 31
  • 48
  • I don't think this can be done. Whether a device is wired or wireless is part of the data link layer. It is transparent to the IP or network layer. – Omair Jan 20 '15 at 10:26
  • Is there any other way to do it in java? – palavesa muthu Jan 20 '15 at 10:46
  • Do you want to find out how the remote machine is connected to the network or what network connection of the local machine is used to reach the remote one? – André Stannek Jan 20 '15 at 10:59

1 Answers1

0

In pure Java, you are limited to what NetworkInterface provides.

Additional information may be found e.g. in this Stackoverflow question.

Community
  • 1
  • 1
Martin C.
  • 10,762
  • 6
  • 38
  • 52
  • Thank You, I want to list the different types of devices connected in my network with its details. Is there any possible,sorry, if it is vague one. – palavesa muthu Jan 20 '15 at 11:12
  • In http://stackoverflow.com/questions/6112489/how-to-get-the-network-interface-type-in-java this is discussed as well. In pure Java this doesn't seem to be available. You could make a guess based on the MTU size, for instance. But this would be very vague. – Martin C. Jan 20 '15 at 11:16
  • We can not get other device's network interface from ours-Is it. please corect me – palavesa muthu Jan 20 '15 at 11:24
  • I am not sure I completly understand the question about other devices, but no, `NetworkInterce.getNetworkInterfaces()` will return your device's network interfaces only, for obvious reasons. – Martin C. Jan 20 '15 at 11:25
  • Thanks a lot, really helpful to me. – palavesa muthu Jan 20 '15 at 11:45
  • I heard that it is possible with SNMP,I don't know how. Any redirection will be really helpful.I want to list the devices(system,router,switch) with its connection mode(wired or wireless) – palavesa muthu Jan 21 '15 at 09:37
  • I think I now get more to what you want, you don't want to know your local (i.e. your computer's) network devices, you want a network scanner. This is something completely different and I did not read that from your question and your tags, but now I understand the initial question better. Please open a new question regarding usage of SNMP (which will only be supported by certain managed devices, though). – Martin C. Jan 21 '15 at 10:46