44 lines
No EOL
1.4 KiB
Java
44 lines
No EOL
1.4 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;
|
|
|
|
public class HTTPHead implements ScanType {
|
|
private String accessString; // Like "http://example.com"
|
|
|
|
public HTTPHead(String accessString) {
|
|
this.accessString = accessString;
|
|
}
|
|
|
|
public static String getName() {
|
|
return "HTTP HEAD";
|
|
}
|
|
|
|
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("HEAD");
|
|
connection.connect();
|
|
int responseCode = connection.getResponseCode();
|
|
connection.disconnect();
|
|
return responseCode == 200; // HTTP OK
|
|
}
|
|
|
|
public String getAccessString() {
|
|
return accessString;
|
|
}
|
|
} |