47 lines
No EOL
1.5 KiB
Java
47 lines
No EOL
1.5 KiB
Java
import java.io.IOException;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URI;
|
|
import java.net.URISyntaxException;
|
|
import java.net.URL;
|
|
import java.net.URLConnection;
|
|
|
|
import javax.rmi.ssl.SslRMIClientSocketFactory;
|
|
|
|
public class HTTPGet implements ScanType {
|
|
private String accessString; // Like "http://example.com"
|
|
|
|
public HTTPGet(String accessString) {
|
|
this.accessString = accessString;
|
|
}
|
|
|
|
public static String getName() {
|
|
return "HTTP GET";
|
|
}
|
|
|
|
static boolean validateAccessString(String accessString) {
|
|
// Validate the access string format (e.g., "http://example.com")
|
|
if (accessString == null || accessString.isEmpty()) {
|
|
return false;
|
|
}
|
|
String regex = "^(http|https)://[a-zA-Z0-9.-]+(:\\d+)?(/.*)?$";
|
|
return accessString.matches(regex);
|
|
}
|
|
|
|
public boolean execute() throws IOException, InterruptedException {
|
|
// Send real HTTP request
|
|
HttpURLConnection connection = HTTPConnection.open(accessString);
|
|
if (!(connection instanceof HttpURLConnection)) {
|
|
throw new IOException("Invalid URL connection type");
|
|
}
|
|
connection.setRequestMethod("GET");
|
|
connection.connect();
|
|
int responseCode = connection.getResponseCode();
|
|
connection.disconnect();
|
|
return responseCode == 200; // HTTP OK
|
|
}
|
|
|
|
public String getAccessString() {
|
|
return accessString;
|
|
}
|
|
} |