mirror of https://github.com/M66B/FairEmail.git
Whois improvements
This commit is contained in:
parent
d1dcdbfb67
commit
596e482f56
|
@ -461,7 +461,7 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
|
||||||
ibInfo.setOnClickListener(new View.OnClickListener() {
|
ibInfo.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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);
|
Helper.view(v.getContext(), uri, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,11 +23,15 @@ import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
public class Whois {
|
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_PORT = 43;
|
||||||
private static final int WHOIS_TIMEOUT = 15 * 1000; // milliseconds
|
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 {
|
static String get(String domain) throws IOException {
|
||||||
return get(domain, getServer(domain), WHOIS_PORT);
|
return get(domain, getServer(domain), WHOIS_PORT);
|
||||||
|
@ -41,19 +45,21 @@ public class Whois {
|
||||||
Socket socket = new Socket();
|
Socket socket = new Socket();
|
||||||
socket.connect(new InetSocketAddress(host, port), WHOIS_TIMEOUT);
|
socket.connect(new InetSocketAddress(host, port), WHOIS_TIMEOUT);
|
||||||
try {
|
try {
|
||||||
socket.getOutputStream().write((domain + "\r\n").getBytes());
|
byte[] request = (domain + "\r\n").getBytes(StandardCharsets.ISO_8859_1);
|
||||||
return host + ":" + port + "\n" + Helper.readStream(socket.getInputStream());
|
socket.getOutputStream().write(request);
|
||||||
|
String response = Helper.readStream(socket.getInputStream(), StandardCharsets.ISO_8859_1);
|
||||||
|
return host + ":" + port + "\n" + response;
|
||||||
} finally {
|
} finally {
|
||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getServer(String domain) throws IOException {
|
private static String getServer(String domain) throws IOException {
|
||||||
String who = get(domain, "whois.iana.org");
|
String iana = get(domain, WHOIS_IANA);
|
||||||
for (String w : who.split("\\r?\\n"))
|
for (String line : iana.split("\\r?\\n"))
|
||||||
if (w.startsWith("whois:"))
|
if (line.startsWith(WHOIS_PREFIX))
|
||||||
return w.substring(6).trim();
|
return line.substring(WHOIS_PREFIX.length()).trim();
|
||||||
Log.w(who);
|
Log.w(iana);
|
||||||
throw new UnknownHostException("whois server unknown " + domain);
|
throw new UnknownHostException("whois server unknown " + domain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue