我是新手,正在尝试通过用户输入的IP地址范围进行增量。比如从192.168.0.1到192.168.0.255。然而,目前我的应用程序处理方式是将“开始”和“结束”IP地址作为字符串。有没有办法逐个遍历用户输入的“开始”和“结束”IP地址?希望这能理解,并请不要责备我,我已经在寻找答案!(注:此处代码略)
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;
}
parseInt
创建一个数字,然后继续进行直到达到255
。 - David Titarenco