forked from I2P_Developers/i2p.i2p
DoH: Add CLI test of all servers
This commit is contained in:
@ -447,10 +447,11 @@ 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_ONLY;
|
||||||
boolean error = false;
|
boolean error = false;
|
||||||
|
boolean testall = false;
|
||||||
String url = null;
|
String url = null;
|
||||||
Getopt g = new Getopt("dnsoverhttps", args, "46fsu:");
|
Getopt g = new Getopt("dnsoverhttps", args, "46fstu:");
|
||||||
try {
|
try {
|
||||||
int c;
|
int c;
|
||||||
while ((c = g.getopt()) != -1) {
|
while ((c = g.getopt()) != -1) {
|
||||||
@ -471,7 +472,17 @@ public class DNSOverHTTPS implements EepGet.StatusListener {
|
|||||||
type = Type.V6_PREFERRED;
|
type = Type.V6_PREFERRED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 't':
|
||||||
|
if (url != null)
|
||||||
|
error = true;
|
||||||
|
else
|
||||||
|
testall = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'u':
|
case 'u':
|
||||||
|
if (testall || url != null)
|
||||||
|
error = true;
|
||||||
|
else
|
||||||
url = g.getOptarg();
|
url = g.getOptarg();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -492,19 +503,46 @@ public class DNSOverHTTPS implements EepGet.StatusListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String hostname = args[g.getOptind()];
|
String hostname = args[g.getOptind()];
|
||||||
|
if (testall) {
|
||||||
|
List<String> totest;
|
||||||
|
if (type == Type.V4_PREFERRED || type == Type.V4_ONLY) {
|
||||||
|
type = Type.V4_ONLY;
|
||||||
|
totest = v4urls;
|
||||||
|
} else {
|
||||||
|
type = Type.V6_ONLY;
|
||||||
|
totest = v6urls;
|
||||||
|
}
|
||||||
|
DNSOverHTTPS doh = new DNSOverHTTPS(I2PAppContext.getGlobalContext());
|
||||||
|
System.out.println("Testing " + totest.size() + " servers");
|
||||||
|
int pass = 0, fail = 0;
|
||||||
|
for (String test : totest) {
|
||||||
|
String result = doh.lookup(hostname, type, test);
|
||||||
|
if (result != null) {
|
||||||
|
pass++;
|
||||||
|
System.out.println(type + " lookup from " + test + " for " + hostname + " is " + result);
|
||||||
|
} else {
|
||||||
|
fail++;
|
||||||
|
System.err.println(type + " lookup from " + test + " failed for " + hostname);
|
||||||
|
}
|
||||||
|
clearCaches();
|
||||||
|
}
|
||||||
|
System.out.println("Test complete: " + pass + " pass, " + fail + " fail");
|
||||||
|
} else {
|
||||||
String result = (new DNSOverHTTPS(I2PAppContext.getGlobalContext())).lookup(hostname, type, url);
|
String result = (new DNSOverHTTPS(I2PAppContext.getGlobalContext())).lookup(hostname, type, url);
|
||||||
if (result != null)
|
if (result != null)
|
||||||
System.out.println(type + " lookup for " + hostname + " is " + result);
|
System.out.println(type + " lookup for " + hostname + " is " + result);
|
||||||
else
|
else
|
||||||
System.err.println(type + " lookup failed for " + hostname);
|
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 [-fstu46] hostname\n" +
|
||||||
" [-f] (IPv4 preferred) (default)\n" +
|
" [-f] (IPv4 preferred)\n" +
|
||||||
" [-s] (IPv6 preferred)\n" +
|
" [-s] (IPv6 preferred)\n" +
|
||||||
|
" [-t] (test all servers)\n" +
|
||||||
" [-u 'https://host/dns-query?...&'] (request from this URL only)\n" +
|
" [-u 'https://host/dns-query?...&'] (request from this URL only)\n" +
|
||||||
" [-4] (IPv4 only)\n" +
|
" [-4] (IPv4 only) (default)\n" +
|
||||||
" [-6] (IPv6 only)");
|
" [-6] (IPv6 only)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user