I’m new to java and i’m trying to find a way of incrementing through an user input IP address range.
For example from 192.168.0.1 to 192.168.0.255. However the way my application works at the moment is the take the from and to ip addresses as a String.
Is there a way I can increment through all the ip addresses the user input from and to?
Hope this makes sense and please dont flame me, I have looked for an answer!
EDIT!
Its actually to ping through the address range so, here’s a little code so far, the ‘host’ is being passed in from another class, which i want to cycle through the addresses:
public static String stringPing(String stringPing, String host){
String ipAddress;
ipAddress = host;
try
{
InetAddress inet = InetAddress.getByName(ipAddress);
boolean status = inet.isReachable(2000);
if (status)
{
stringPing = "\n" +host +" is reachable";
return stringPing;
}
else
{
stringPing = "\n" +host +" is unreachable";
return stringPing;
}
}
catch (UnknownHostException e)
{
System.err.println("Host does not exists");
}
catch (IOException e)
{
System.err.println("Error in reaching the Host");
}
return stringPing;
}
Hold address as it should be — as 32-bit integer, and increment it in this form. Convert it from or to
Stringonly if required. Example is below. MyIPAddressclass is complete and functional.