本文介绍了如何在Java中检查子域的有效性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个域abc.jp
例如:
我想检查是否有效,可以在此示例中添加另一个子域.怎么做?如果可能,请上传一些Java代码作为参考吗?
谢谢
I have a domain abc.jp
For example:
I want to check if this is valid to that I can add another sublevel domain to this example. How to do it? If possible, upload some java codes as reference please?
Thank you
推荐答案
您的示例ac.jp是有效域,但不是IP可解析域.因此,我建议使用Whois服务器.如果要检查所有域,则需要保留许多Whois服务器.如果您仅在日本使用,则下面的代码片段应该可以使用™.
Your example ac.jp is a valid domain, but not an IP resolvable domain. So I would suggest a whois server. You would need to keep a number of whois servers if you want to check all domains. If you only do Japan then the below snippet should work™.
import org.apache.commons.net.whois.*;
public class Main {
public static void main(String[] args) {
WhoisClient whois = new WhoisClient();
String whoishost = "whois.jprs.jp";
// String whoishost = "whois.verisign-grs.com"; // for .com domains
String domain = "ac.jp";
try {
whois.connect(whoishost);
String whoisData = whois.query(domain);
if (whoisData.toUpperCase().contains("NO MATCH")){
System.out.println("Domain is not registered. According to whoishost: " + whoishost);
}
else{
System.out.println("Domain is registered. According to whoishost: " + whoishost);
}
} catch (java.io.IOException ioex) {
System.out.println("failed");
}
}
}
这篇关于如何在Java中检查子域的有效性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!