IP address of remote device in a LAN using Java
i have written a code that should give me the ip addresses of all the devices connected in a wireless network.But it is just showing the ip address of the default gateway router and my own system. so plz can someone help me with this.
importjava.io.IOException;
importjava.net.InetAddress;
publicclass NetworkPing {
publicstaticvoid main(String[] args)throws IOException {
InetAddress localhost = InetAddress.getLocalHost();
// this code assumes IPv4 is used
byte[] ip = localhost.getAddress();
for(int i =1; i <=254; i++)
{
ip[3]=(byte)i;
InetAddress address = InetAddress.getByAddress(ip);
if(address.isReachable(1000))
{
System.out.println(address +" machine is turned on and can be pinged");
}
elseif(!address.getHostAddress().equals(address.getHostName()))
{
System.out.println(address +" machine is known in a DNS lookup");
}
else
{
System.out.println(address +" the host address and host name are equal, meaning the host name could not be resolved");
}
}
}
}
0