获取顶级域名

//获取域名的函数
//包含全部的cn域名后缀
static String[] xCN = { ".com.cn", ".net.cn", ".gov.cn", ".edu.cn",
".org.cn", ".mil.cn", ".ac.cn", ".bj.cn", ".sh.cn", ".tj.cn",
".cq.cn", ".he.cn", ".sx.cn", ".nm.cn", ".ln.cn", ".jl.cn",
".hl.cn", ".js.cn", ".zj.cn", ".ah.cn", ".fj.cn", ".jx.cn",
".sd.cn", ".ha.cn", ".hb.cn", ".hn.cn", ".gd.cn", ".gx.cn",
".hi.cn", ".sc.cn", ".gz.cn", ".yn.cn", ".xz.cn", ".sn.cn",
".gs.cn", ".qh.cn", ".nx.cn", ".xj.cn", ".tw.cn", ".hk.cn",
".mo.cn" };

public static String getHost1(String host) {
host = host.trim().toLowerCase();//格式化
String domain1 = "";
if (host.endsWith(".cn")) {
//判断cn分类域名以及区域域名
for (int i = 0; i < xCN.length; i++) {
if (host.endsWith(xCN[i])) {
host = host.substring(0, host.length() - xCN[i].length());
String[] _s = host.split("\\.");
if (_s.length > 0) {
domain1 = _s[_s.length - 1] + xCN[i];
}
return domain1;
}
}
//else if(host.endsWith(".cn")){
host = host.substring(0, host.length() - 3);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".cn";
//}
} else if (host.endsWith(".com")) {
host = host.substring(0, host.length() - 4);
String[] _s = host.split("\\.");
domain1 = _s[_s.length - 1] + ".com";
}

else if (host.endsWith(".net")) {
host = host.substring(0, host.length() - 4);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".net";
}

else if (host.endsWith(".org")) {
host = host.substring(0, host.length() - 4);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".org";
}

else if (host.endsWith(".gov")) {
host = host.substring(0, host.length() - 4);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".gov";
}

else if (host.endsWith(".edu")) {
host = host.substring(0, host.length() - 4);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".edu";
}

else if (host.endsWith(".biz")) {
host = host.substring(0, host.length() - 4);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".biz";
}

else if (host.endsWith(".tv")) {
host = host.substring(0, host.length() - 3);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".tv";
}

else if (host.endsWith(".cc")) {
host = host.substring(0, host.length() - 3);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".cc";
}

else if (host.endsWith(".be")) {
host = host.substring(0, host.length() - 3);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".be";
}

else if (host.endsWith(".info")) {
host = host.substring(0, host.length() - 5);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".info";
}

else if (host.endsWith(".name")) {
host = host.substring(0, host.length() - 5);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".name";
}

else if (host.endsWith(".co.uk")) {
host = host.substring(0, host.length() - 6);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".co.uk";
}

else if (host.endsWith(".me.uk")) {
host = host.substring(0, host.length() - 6);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".me.uk";
}

else if (host.endsWith(".org.uk")) {
host = host.substring(0, host.length() - 7);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".org.uk";
}

else if (host.endsWith(".ltd.uk")) {
host = host.substring(0, host.length() - 7);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".ltd.uk";
}

else if (host.endsWith(".plc.uk")) {
host = host.substring(0, host.length() - 7);
String[] _s = host.split("\\.");
if (_s.length > 0)
domain1 = _s[_s.length - 1] + ".plc.uk";
}
return domain1;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值