I'm looking for a better way to get the computer names in my LAN network with Java. I have tried:
byte[] ip = {(byte)192,(byte)168,(byte)178,(byte)1};
for(int i=1;i<255;i++)
{
ip[3] = (byte)i;
try
{
InetAddress addr = InetAddress.getByAddress(ip);
String s = addr.getHostName();
System.out.println(s);
}
catch(UnknownHostException e)
{
System.out.println(e.getMessage());
}
}
... but it's too slow. Is there any other way?
I am on Windows.
Any ideas are appreciated.
You can increase speed by using multiple threads.
Have each thread execute one or more of the iterations of your 'try' block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With