36 lines
1.1 KiB
Java
36 lines
1.1 KiB
Java
import java.io.IOException;
|
|
|
|
public class Ping implements ScanType {
|
|
private String accessString;
|
|
|
|
public Ping(String accessString) {
|
|
this.accessString = accessString;
|
|
}
|
|
|
|
public static String getName() {
|
|
return "Ping";
|
|
}
|
|
|
|
static boolean validateAccessString(String accessString) {
|
|
// Validate the access string format (e.g., "example.com")
|
|
if (accessString == null || accessString.isEmpty()) {
|
|
return false;
|
|
}
|
|
String regex = "^[a-zA-Z0-9.-]+$";
|
|
return accessString.matches(regex);
|
|
}
|
|
|
|
public boolean execute() throws IOException, InterruptedException {
|
|
boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win");
|
|
|
|
ProcessBuilder processBuilder = new ProcessBuilder("ping", isWindows? "-n" : "-c", "1", accessString);
|
|
Process proc = processBuilder.start();
|
|
|
|
int returnVal = proc.waitFor();
|
|
return returnVal == 0;
|
|
}
|
|
|
|
public String getAccessString() {
|
|
return accessString;
|
|
}
|
|
}
|