This is my code which tells the status of PING of an IP address. However, I cannot get it to append the output using printstream and instead of using so many ip addresses I wish to use Loop so that i have t use it just once. A little help would be appreciated.
PrintStream out;
out = new PrintStream(new FileOutputStream("output1.csv"));
System.setOut(out);
String ipAddress = "172.20.10.13";
InetAddress inet = InetAddress.getByName(ipAddress);
System.out.println("Sending Ping Request to " + ipAddress);
System.out.println(inet.isReachable(1000) ? "Host is reachable" : "Host is NOT reachable");
out = new PrintStream(new FileOutputStream("output7.csv"));
System.setOut(out);
ipAddress = "192.168.1.10";
inet = InetAddress.getByName(ipAddress);
System.out.println("Sending Ping Request to " + ipAddress);
System.out.println(inet.isReachable(1000) ? "Host is reachable" : "Host is NOT reachable");
out = new PrintStream(new FileOutputStream("output10.csv"));
System.setOut(out);
ipAddress = "192.168.1.35";
inet = InetAddress.getByName(ipAddress);
System.out.println("Sending Ping Request to " + ipAddress);
System.out.println(inet.isReachable(1000) ? "Host is reachable" : "Host is NOT reachable");