Support loading HTTP requests from file

This commit is contained in:
SearchNull
2021-12-28 23:55:50 +08:00
parent dc83331954
commit 6eeb047d22

View File

@@ -12,14 +12,16 @@ import java.util.*;
* @author SearchNull
*/
public class StartUp {
public static String url;
public static String method;
public static Map<String, String> headers;
public static String body;
private static Map<String, String> options;
private static LDAPServer ldapServer;
private static String ip;
private static int port;
private static String url;
private static String method;
private static Map<String, String> headers;
private static String body;
private static String file;
private static Proxy proxy;
private static Scanner sc;
private static String command;
@@ -50,7 +52,7 @@ public class StartUp {
Parser parser = new Parser();
options = parser.parse(args);
if (options.get("ip") == null || options.get("url") == null) {
if (options.get("ip") == null || (options.get("url") == null && options.get("file") == null)) {
printUsage();
System.exit(1);
} else {
@@ -67,10 +69,22 @@ public class StartUp {
private static void initial() {
ip = options.get("ip");
port = Integer.parseInt(options.get("port") == null ? "1389" : options.get("port"));
url = options.get("url");
method = options.get("method") == null ? "GET" : options.get("method");
headers = Parser.parseHeaders(options.get("headers"));
body = options.get("body");
if (options.get("url") == null && options.get("file") != null) {
file = options.get("file");
try {
HttpUtil.formatHttp(file);
} catch (IOException ioException) {
System.out.println("请检查 " + file + " 是否存在!");
ioException.printStackTrace();
System.exit(1);
}
} else {
url = options.get("url");
method = options.get("method") == null ? "GET" : options.get("method");
headers = Parser.parseHeaders(options.get("headers"));
body = options.get("body");
}
if (options.get("proxy") != null) {
String[] proxies = options.get("proxy").split(":", 2);
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxies[0], Integer.parseInt(proxies[1])));
@@ -101,6 +115,7 @@ public class StartUp {
" ip LDAP Server IP如VPS则指定公网IP\n" +
" port LDAP Server 监听端口默认为1389\n" +
" url 目标URL指定headers和body参数可发送完整HTTP请求\n" +
" file 指定HTTP请求数据包的文件将根据该文件内容构造完整HTTP请求\n" +
" method 指定HTTP请求方法默认为GET\n" +
" headers 指定HTTP请求头以分号分隔多个请求头以=分隔key,value\n" +
" body 指定HTTP请求体内容\n" +