Hey folks, recently I wrote a small application in java where it generates ip addresses in a 192.168.x.x block, and then proceeds to ping them to see if the address is available or not.
The main issue with it right now is that it's extremely slow when I tested it in a network, and so sometimes it takes 10 minutes just to finish up an address beginning with 192.168.1.x, before proceeding with the following block.
I'm still unclear on multithreading, so I was wondering if anyone here can show me how to implement it into my code.
Here's my code:
import java.io.*;
import java.net.*;
import java.net.InetAddress;
public class pingBlock
{
public static void main(String args[])
{
int oct1, oct2;
for(oct1 = 1; oct1 <=255; oct1++)
{
for(oct2 = 1; oct2 <=255; oct2++)
try
{
InetAddress address = InetAddress.getByName(String.format("192.168.%d.%d", oct1, oct2));
boolean reachable = address.isReachable(1000);
System.out.println("Addr: " + address.getHostAddress());
System.out.println("Reach: " + address.isReachable(3000));
}
catch (UnknownHostException e)
{
System.out.println("unable to look up IP Address block");
}
catch (IOException e)
{
System.out.println("unable to look up IP Address block");
}
}
}
}