Whois improvements

pull/209/head
M66B 2 years ago
parent d1dcdbfb67
commit 596e482f56

@ -461,7 +461,7 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
ibInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("https://en.wikipedia.org/wiki/WHOIS");
Uri uri = Uri.parse(Whois.WHOIS_INFO);
Helper.view(v.getContext(), uri, true);
}
});

@ -23,11 +23,15 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
public class Whois {
// https://datatracker.ietf.org/doc/html/rfc812
// https://datatracker.ietf.org/doc/html/rfc3912
static final String WHOIS_INFO = "https://en.wikipedia.org/wiki/WHOIS";
private static final int WHOIS_PORT = 43;
private static final int WHOIS_TIMEOUT = 15 * 1000; // milliseconds
private static final String WHOIS_IANA = "whois.iana.org";
private static final String WHOIS_PREFIX = "whois:";
static String get(String domain) throws IOException {
return get(domain, getServer(domain), WHOIS_PORT);
@ -41,19 +45,21 @@ public class Whois {
Socket socket = new Socket();
socket.connect(new InetSocketAddress(host, port), WHOIS_TIMEOUT);
try {
socket.getOutputStream().write((domain + "\r\n").getBytes());
return host + ":" + port + "\n" + Helper.readStream(socket.getInputStream());
byte[] request = (domain + "\r\n").getBytes(StandardCharsets.ISO_8859_1);
socket.getOutputStream().write(request);
String response = Helper.readStream(socket.getInputStream(), StandardCharsets.ISO_8859_1);
return host + ":" + port + "\n" + response;
} finally {
socket.close();
}
}
private static String getServer(String domain) throws IOException {
String who = get(domain, "whois.iana.org");
for (String w : who.split("\\r?\\n"))
if (w.startsWith("whois:"))
return w.substring(6).trim();
Log.w(who);
String iana = get(domain, WHOIS_IANA);
for (String line : iana.split("\\r?\\n"))
if (line.startsWith(WHOIS_PREFIX))
return line.substring(WHOIS_PREFIX.length()).trim();
Log.w(iana);
throw new UnknownHostException("whois server unknown " + domain);
}
}

Loading…
Cancel
Save