import java.net.*;
public class myIP {
public static void main (String argv[])
{
try{
InetAddress ownIP=InetAddress.getLocalHost();
String myIP = ownIP.getHostAddress();
System.out.println( "IP of my system is := "+ myIP );
}catch (Exception e){
System.out.println( "Exception caught ="+e.getMessage() );
}
}
}
This piece of code retrieves the machine's IP address. With this information (my own IP address), I'd want to search for other IP addresses in this range to automatically locate the server.
I'm at a loss as to how to iterate through this IP range. For example, if "myIP" is 10.0.0.5, how can I change that string to, say, 10.0.0.6? If it were an integer number, it would be simple to add 1 every time - but since it's a string - separated by dots - I'm stumped:) any suggestions?