首页 WHOIS查询 WHOIS查询示例代码 域名查询[Java]

域名查询示例代码[Java]

作者:xiezhongpian 阅读数:1897 上传时间:2017-05-09

域名查询

package api.jisuapi.whois;

import api.util.HttpUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Query {

	public static final String APPKEY = "your_appkey_here";// 你的appkey
	public static final String URL = "https://api.jisuapi.com/whois/query";
	public static final String domain = "jisuapi.com";// 域名

	public static void Get() {
		String result = null;
		String url = URL + "?appkey=" + APPKEY + "&domain=" + domain;

		try {
			result = HttpUtil.sendGet(url, "utf-8");
			JSONObject json = JSONObject.fromObject(result);
			if (json.getInt("status") != 0) {
				System.out.println(json.getString("msg"));
			} else {
				JSONObject resultarr = json.optJSONObject("result");
				String domain = resultarr.getString("domain");
				String registered = resultarr.getString("registered");
				System.out.println(domain + " " + registered);
				if (resultarr.opt("registrarinfo") != null) {
					JSONObject registrarinfo = resultarr.optJSONObject("registrarinfo");
					String registrar = registrarinfo.getString("registrar");
					String whois = registrarinfo.getString("whois");
					String referrer = registrarinfo.getString("referrer");
					System.out.println(registrar + " " + whois + " " + referrer);
				}
				if (resultarr.opt("nserver") != null) {
					JSONObject nserver = resultarr.optJSONObject("nserver");
					String f1g1ns1 = nserver.getString("f1g1ns1.dnspod.net");
					String f1g1ns2 = nserver.getString("f1g1ns2.dnspod.net");
					System.out.println(f1g1ns1 + " " + f1g1ns2);
				}
				JSONArray status = resultarr.optJSONArray("status");
				for (int i = 0; i < status.size(); i++) {
					System.out.println(status.get(i));
				}
				String changed = resultarr.getString("changed");
				String created = resultarr.getString("created");
				String expires = resultarr.getString("expires");
				System.out.println(changed + " " + created + " " + expires);
				JSONArray statuscn = resultarr.optJSONArray("statuscn");
				for (int i = 0; i < statuscn.size(); i++) {
					System.out.println(statuscn.get(i));
				}
				JSONArray rawdata = resultarr.optJSONArray("rawdata");
				for (int i = 0; i < rawdata.size(); i++) {
					System.out.println(rawdata.get(i));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}