获取顶级域名的java实现的函数

  1. //获取域名的函数  
  2.     //包含全部的cn域名后缀  
  3.     static String[] xCN = { ".com.cn"".net.cn"".gov.cn"".edu.cn",  
  4.             ".org.cn"".mil.cn"".ac.cn"".bj.cn"".sh.cn"".tj.cn",  
  5.             ".cq.cn"".he.cn"".sx.cn"".nm.cn"".ln.cn"".jl.cn",  
  6.             ".hl.cn"".js.cn"".zj.cn"".ah.cn"".fj.cn"".jx.cn",  
  7.             ".sd.cn"".ha.cn"".hb.cn"".hn.cn"".gd.cn"".gx.cn",  
  8.             ".hi.cn"".sc.cn"".gz.cn"".yn.cn"".xz.cn"".sn.cn",  
  9.             ".gs.cn"".qh.cn"".nx.cn"".xj.cn"".tw.cn"".hk.cn",  
  10.             ".mo.cn" };  
  11.   
  12.     public static String getHost1(String host) {  
  13.         host = host.trim().toLowerCase();//格式化  
  14.         String domain1 = "";  
  15.         if (host.endsWith(".cn")) {  
  16.             //判断cn分类域名以及区域域名  
  17.             for (int i = 0; i < xCN.length; i++) {  
  18.                 if (host.endsWith(xCN[i])) {  
  19.                     host = host.substring(0, host.length() - xCN[i].length());  
  20.                     String[] _s = host.split("\\.");  
  21.                     if (_s.length > 0) {  
  22.                         domain1 = _s[_s.length - 1] + xCN[i];  
  23.                     }  
  24.                     return domain1;  
  25.                 }  
  26.             }  
  27.             //else if(host.endsWith(".cn")){  
  28.             host = host.substring(0, host.length() - 3);  
  29.             String[] _s = host.split("\\.");  
  30.             if (_s.length > 0)  
  31.                 domain1 = _s[_s.length - 1] + ".cn";  
  32.             //}  
  33.         } else if (host.endsWith(".com")) {  
  34.             host = host.substring(0, host.length() - 4);  
  35.             String[] _s = host.split("\\.");  
  36.             domain1 = _s[_s.length - 1] + ".com";  
  37.         }  
  38.   
  39.         else if (host.endsWith(".net")) {  
  40.             host = host.substring(0, host.length() - 4);  
  41.             String[] _s = host.split("\\.");  
  42.             if (_s.length > 0)  
  43.                 domain1 = _s[_s.length - 1] + ".net";  
  44.         }  
  45.   
  46.         else if (host.endsWith(".org")) {  
  47.             host = host.substring(0, host.length() - 4);  
  48.             String[] _s = host.split("\\.");  
  49.             if (_s.length > 0)  
  50.                 domain1 = _s[_s.length - 1] + ".org";  
  51.         }  
  52.   
  53.         else if (host.endsWith(".gov")) {  
  54.             host = host.substring(0, host.length() - 4);  
  55.             String[] _s = host.split("\\.");  
  56.             if (_s.length > 0)  
  57.                 domain1 = _s[_s.length - 1] + ".gov";  
  58.         }  
  59.   
  60.         else if (host.endsWith(".edu")) {  
  61.             host = host.substring(0, host.length() - 4);  
  62.             String[] _s = host.split("\\.");  
  63.             if (_s.length > 0)  
  64.                 domain1 = _s[_s.length - 1] + ".edu";  
  65.         }  
  66.   
  67.         else if (host.endsWith(".biz")) {  
  68.             host = host.substring(0, host.length() - 4);  
  69.             String[] _s = host.split("\\.");  
  70.             if (_s.length > 0)  
  71.                 domain1 = _s[_s.length - 1] + ".biz";  
  72.         }  
  73.   
  74.         else if (host.endsWith(".tv")) {  
  75.             host = host.substring(0, host.length() - 3);  
  76.             String[] _s = host.split("\\.");  
  77.             if (_s.length > 0)  
  78.                 domain1 = _s[_s.length - 1] + ".tv";  
  79.         }  
  80.   
  81.         else if (host.endsWith(".cc")) {  
  82.             host = host.substring(0, host.length() - 3);  
  83.             String[] _s = host.split("\\.");  
  84.             if (_s.length > 0)  
  85.                 domain1 = _s[_s.length - 1] + ".cc";  
  86.         }  
  87.   
  88.         else if (host.endsWith(".be")) {  
  89.             host = host.substring(0, host.length() - 3);  
  90.             String[] _s = host.split("\\.");  
  91.             if (_s.length > 0)  
  92.                 domain1 = _s[_s.length - 1] + ".be";  
  93.         }  
  94.   
  95.         else if (host.endsWith(".info")) {  
  96.             host = host.substring(0, host.length() - 5);  
  97.             String[] _s = host.split("\\.");  
  98.             if (_s.length > 0)  
  99.                 domain1 = _s[_s.length - 1] + ".info";  
  100.         }  
  101.   
  102.         else if (host.endsWith(".name")) {  
  103.             host = host.substring(0, host.length() - 5);  
  104.             String[] _s = host.split("\\.");  
  105.             if (_s.length > 0)  
  106.                 domain1 = _s[_s.length - 1] + ".name";  
  107.         }  
  108.   
  109.         else if (host.endsWith(".co.uk")) {  
  110.             host = host.substring(0, host.length() - 6);  
  111.             String[] _s = host.split("\\.");  
  112.             if (_s.length > 0)  
  113.                 domain1 = _s[_s.length - 1] + ".co.uk";  
  114.         }  
  115.   
  116.         else if (host.endsWith(".me.uk")) {  
  117.             host = host.substring(0, host.length() - 6);  
  118.             String[] _s = host.split("\\.");  
  119.             if (_s.length > 0)  
  120.                 domain1 = _s[_s.length - 1] + ".me.uk";  
  121.         }  
  122.   
  123.         else if (host.endsWith(".org.uk")) {  
  124.             host = host.substring(0, host.length() - 7);  
  125.             String[] _s = host.split("\\.");  
  126.             if (_s.length > 0)  
  127.                 domain1 = _s[_s.length - 1] + ".org.uk";  
  128.         }  
  129.   
  130.         else if (host.endsWith(".ltd.uk")) {  
  131.             host = host.substring(0, host.length() - 7);  
  132.             String[] _s = host.split("\\.");  
  133.             if (_s.length > 0)  
  134.                 domain1 = _s[_s.length - 1] + ".ltd.uk";  
  135.         }  
  136.   
  137.         else if (host.endsWith(".plc.uk")) {  
  138.             host = host.substring(0, host.length() - 7);  
  139.             String[] _s = host.split("\\.");  
  140.             if (_s.length > 0)  
  141.                 domain1 = _s[_s.length - 1] + ".plc.uk";  
  142.         }  
  143.         return domain1;  
  144.     }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值