Я хочу через Whois-сервер выводить информацию о домене.Допустим, для начала я хочу отобразить информацию о домене (google.com) Но он не отображает информацию у меня, вы можете сказать, в чем проблема.Я вроде как написал код правильно, возможно я где-то допустил ошибку.
import org.apache.commons.net.whois.WhoisClient;
import java.io.IOException;
import java.net.SocketException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WhoisTest {
private static Pattern pattern;
private Matcher matcher;
private static final String WHOIS_SERVER_PATTERN = "Whois Server:\\s(.*)";
static {
pattern = Pattern.compile(WHOIS_SERVER_PATTERN);
}
public static void main(String[] args) {
WhoisTest obj = new WhoisTest();
System.out.println(obj.getWhois("google.com"));
System.out.println("Done");
}
public String getWhois(String domainName) {
StringBuilder result = new StringBuilder("");
WhoisClient whois = new WhoisClient();
try {
whois.connect(WhoisClient.DEFAULT_HOST);
String whoisData1 = whois.query("=" + domainName);
result.append(whoisData1);
whois.disconnect();
String whoisServerUrl = getWhoisServer(whoisData1);
if (!whoisServerUrl.equals("")) {
String whoisData2 =
queryWithWhoisServer(domainName, whoisServerUrl);
result.append(whoisData2);
}
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result.toString();
}
private String queryWithWhoisServer(String domainName, String whoisServer) {
String result = "";
WhoisClient whois = new WhoisClient();
try {
whois.connect(whoisServer);
result = whois.query(domainName);
whois.disconnect();
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
private String getWhoisServer(String whois) {
String result = "";
matcher = pattern.matcher(whois);
while (matcher.find()) {
result = matcher.group(1);
}
return result;
}
}
Но он отображает только
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 21.382s
Finished at: Thu Sep 19 10:50:30 BDT 2019
Final Memory: 5M/243M
Хотя он должен вывести это
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
//......
Registrant:
Dns Admin
Google Inc.
Please contact contact-admin@google.com 1600 Amphitheatre Parkway
Mountain View CA 94043
US
dns-admin@google.com +1.6502530000 Fax: +1.6506188571
Domain Name: google.com
Registrar Name: Markmonitor.com
Registrar Whois: whois.markmonitor.com
Registrar Homepage: http://www.markmonitor.com
//......
Created on..............: 1997-09-15.
Expires on..............: 2020-09-13.
Record last updated on..: 2013-02-28.
//......