DoH: Add more CLI options for testing

This commit is contained in:
zzz
2020-10-26 15:29:59 +00:00
parent cf88b3057a
commit ab55f27ea4
2 changed files with 39 additions and 10 deletions

View File

@ -141,6 +141,16 @@ public class DNSOverHTTPS implements EepGet.StatusListener {
* @return null if not found * @return null if not found
*/ */
public String lookup(String host, Type type) { public String lookup(String host, Type type) {
return lookup(host, type, null);
}
/**
* Lookup in cache, then query servers
* @param url null to query several default servers, or specify single server
* @return null if not found
* @since 0.9.48
*/
private String lookup(String host, Type type, String url) {
if (Addresses.isIPAddress(host)) if (Addresses.isIPAddress(host))
return host; return host;
if (host.startsWith("[")) if (host.startsWith("["))
@ -175,7 +185,7 @@ public class DNSOverHTTPS implements EepGet.StatusListener {
if (rv != null) if (rv != null)
return rv; return rv;
} }
return query(host, type); return query(host, type, url);
} }
public static void clearCaches() { public static void clearCaches() {
@ -206,10 +216,15 @@ public class DNSOverHTTPS implements EepGet.StatusListener {
/** /**
* Query servers * Query servers
* @param url null to query several default servers, or specify single server
* @return null if not found * @return null if not found
*/ */
private String query(String host, Type type) { private String query(String host, Type type, String url) {
List<String> toQuery = new ArrayList<String>((type == Type.V6_ONLY) ? v6urls : v4urls); List<String> toQuery;
if (url != null)
toQuery = Collections.singletonList(url);
else
toQuery = new ArrayList<String>((type == Type.V6_ONLY) ? v6urls : v4urls);
Collections.shuffle(toQuery); Collections.shuffle(toQuery);
final long timeout = System.currentTimeMillis() + OVERALL_TIMEOUT; final long timeout = System.currentTimeMillis() + OVERALL_TIMEOUT;
if (type == Type.V4_ONLY || type == Type.V4_PREFERRED) { if (type == Type.V4_ONLY || type == Type.V4_PREFERRED) {
@ -430,7 +445,8 @@ public class DNSOverHTTPS implements EepGet.StatusListener {
public static void main(String[] args) { public static void main(String[] args) {
Type type = Type.V4_PREFERRED; Type type = Type.V4_PREFERRED;
boolean error = false; boolean error = false;
Getopt g = new Getopt("dnsoverhttps", args, "46fs"); String url = null;
Getopt g = new Getopt("dnsoverhttps", args, "46fsu:");
try { try {
int c; int c;
while ((c = g.getopt()) != -1) { while ((c = g.getopt()) != -1) {
@ -451,6 +467,10 @@ public class DNSOverHTTPS implements EepGet.StatusListener {
type = Type.V6_PREFERRED; type = Type.V6_PREFERRED;
break; break;
case 'u':
url = g.getOptarg();
break;
case '?': case '?':
case ':': case ':':
default: default:
@ -467,18 +487,19 @@ public class DNSOverHTTPS implements EepGet.StatusListener {
System.exit(1); System.exit(1);
} }
String url = args[g.getOptind()]; String hostname = args[g.getOptind()];
String result = (new DNSOverHTTPS(I2PAppContext.getGlobalContext())).lookup(url, type); String result = (new DNSOverHTTPS(I2PAppContext.getGlobalContext())).lookup(hostname, type, url);
if (result != null) if (result != null)
System.out.println(type + " lookup for " + url + " is " + result); System.out.println(type + " lookup for " + hostname + " is " + result);
else else
System.err.println(type + " lookup failed for " + url); System.err.println(type + " lookup failed for " + hostname);
} }
private static void usage() { private static void usage() {
System.err.println("DNSOverHTTPS [-fs46] hostname\n" + System.err.println("DNSOverHTTPS [-fs46] hostname\n" +
" [-f] (IPv4 preferred) (default)\n" + " [-f] (IPv4 preferred) (default)\n" +
" [-s] (IPv6 preferred)\n" + " [-s] (IPv6 preferred)\n" +
" [-u 'https://host/dns-query?...&'] (request from this URL only)\n" +
" [-4] (IPv4 only)\n" + " [-4] (IPv4 only)\n" +
" [-6] (IPv6 only)"); " [-6] (IPv6 only)");
} }

View File

@ -263,8 +263,9 @@ public class SSLEepGet extends EepGet {
String proxyHost = "127.0.0.1"; String proxyHost = "127.0.0.1";
int proxyPort = 0; int proxyPort = 0;
ProxyType ptype = ProxyType.NONE; ProxyType ptype = ProxyType.NONE;
boolean doh = false;
boolean error = false; boolean error = false;
Getopt g = new Getopt("ssleepget", args, "p:y:sz"); Getopt g = new Getopt("ssleepget", args, "dp:y:sz");
try { try {
int c; int c;
while ((c = g.getopt()) != -1) { while ((c = g.getopt()) != -1) {
@ -308,6 +309,10 @@ public class SSLEepGet extends EepGet {
noVerify = true; noVerify = true;
break; break;
case 'd':
doh = true;
break;
case '?': case '?':
case ':': case ':':
default: default:
@ -347,6 +352,8 @@ public class SSLEepGet extends EepGet {
get._saveCerts = saveCerts; get._saveCerts = saveCerts;
if (noVerify) if (noVerify)
get._bypassVerification = true; get._bypassVerification = true;
if (doh)
get.forceDNSOverHTTPS(true);
get._commandLine = true; get._commandLine = true;
get.addStatusListener(get.new CLIStatusListener(1024, 40)); get.addStatusListener(get.new CLIStatusListener(1024, 40));
if(!get.fetch(45*1000, -1, 60*1000)) if(!get.fetch(45*1000, -1, 60*1000))
@ -354,7 +361,8 @@ public class SSLEepGet extends EepGet {
} }
private static void usage() { private static void usage() {
System.err.println("Usage: SSLEepGet [-psyz] https://url\n" + System.err.println("Usage: SSLEepGet [-dpsyz] https://url\n" +
" -d use DNSOverHTTPS\n" +
" -p proxyHost[:proxyPort] // default port 8080 for HTTPS and 1080 for SOCKS; default localhost:4444 for I2P\n" + " -p proxyHost[:proxyPort] // default port 8080 for HTTPS and 1080 for SOCKS; default localhost:4444 for I2P\n" +
" -y HTTPS|SOCKS4|SOCKS5|I2P // proxy type, default HTTPS if proxyHost is set\n" + " -y HTTPS|SOCKS4|SOCKS5|I2P // proxy type, default HTTPS if proxyHost is set\n" +
" -s save unknown certs\n" + " -s save unknown certs\n" +