2022-09-04 06:44:09 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This file is part of FairEmail.
|
|
|
|
|
|
|
|
FairEmail is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
FairEmail is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Copyright 2018-2022 by Marcel Bokhorst (M66B)
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.Socket;
|
2022-09-04 08:09:05 +00:00
|
|
|
import java.net.UnknownHostException;
|
2022-09-04 06:44:09 +00:00
|
|
|
|
|
|
|
public class Whois {
|
|
|
|
private static final int WHOIS_PORT = 43;
|
|
|
|
|
|
|
|
static String get(String domain) throws IOException {
|
2022-09-04 08:09:05 +00:00
|
|
|
return get(domain, getServer(domain), WHOIS_PORT);
|
2022-09-04 06:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static String get(String domain, String host) throws IOException {
|
|
|
|
return get(domain, host, WHOIS_PORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static String get(String domain, String host, int port) throws IOException {
|
|
|
|
try (Socket socket = new Socket(host, port)) {
|
|
|
|
socket.getOutputStream().write((domain + "\n").getBytes());
|
2022-09-04 08:09:05 +00:00
|
|
|
return host + ":" + port + "\n" + Helper.readStream(socket.getInputStream());
|
2022-09-04 06:44:09 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-04 08:09:05 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
throw new UnknownHostException("whois server unknown " + domain);
|
|
|
|
}
|
2022-09-04 06:44:09 +00:00
|
|
|
}
|