zoukankan      html  css  js  c++  java
  • 域名查询源码

     
    1. using System;
    2. using System.Data;
    3. using System.Configuration;
    4. using System.Web;
    5. using System.Web.Security;
    6. using System.Web.UI;
    7. using System.Web.UI.WebControls;
    8. using System.Web.UI.WebControls.WebParts;
    9. using System.Web.UI.HtmlControls;
    10. using System.Net;
    11. using System.Net.Sockets;
    12. using System.Text;
    13. using System.Collections;
    14. using System.Text.RegularExpressions;
    15. /// <summary>
    16. /// SelectYuMing 的摘要说明
    17. /// </summary>
    18. public class SelectYuMing
    19. {
    20.     public SelectYuMing()
    21.     {
    22.         //
    23.         // TODO: 在此处添加构造函数逻辑
    24.         //
    25.     }
    26.     /**/
    27.     /// <summary>
    28.     /// 域名注册查询
    29.     /// </summary>
    30.     /// <param name="domain">输入域名,不包含www</param>
    31.     /// <returns></returns>
    32.     public static string Whois(string domain)
    33.     {
    34.         if (domain == null)
    35.             throw new ArgumentNullException();//如果输入为空 就抛出一个空异常(停止程序的执行)
    36.         int ccStart = domain.LastIndexOf(".");//
    37.         if (ccStart < 0 || ccStart == domain.Length)
    38.             throw new ArgumentException();
    39.         string ret = "";
    40.         Socket s = null;
    41.         try
    42.         {
    43.             string cc = domain.Substring(ccStart + 1);
    44.             s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    45.             s.Connect(new IPEndPoint(Dns.Resolve(cc + ".whois-servers.net").AddressList[0], 43));
    46.             s.Send(Encoding.ASCII.GetBytes(domain + "/r/n"));
    47.             byte[] buffer = new byte[1024];
    48.             int recv = s.Receive(buffer);
    49.             while (recv > 0)
    50.             {
    51.                 ret += Encoding.ASCII.GetString(buffer, 0, recv);
    52.                 recv = s.Receive(buffer);
    53.             }
    54.             s.Shutdown(SocketShutdown.Both);
    55.         }
    56.         catch
    57.         {
    58.             throw new SocketException();
    59.         }
    60.         finally
    61.         {
    62.             if (s != null)
    63.                 s.Close();
    64.         }
    65.         return ret;
    66.     }
    67.     /// <summary>
    68.     ///  查询域名是否存在
    69.     /// </summary>
    70.     /// <param name="str">所有的后缀的集合(com|cn|com.cn|hk|.net|mobi|asia|)</param>
    71.     /// <param name="strYuMing"></param>
    72.     /// <returns></returns>
    73.     public ArrayList SelectYu(ArrayList str,string strYuMing) 
    74.     {
    75.         ArrayList arr=new ArrayList();
    76.         foreach(string strYu in str)
    77.         {
    78.             try
    79.             {
    80.                 string strManage = Whois(strYuMing + strYu);
    81.                 Boolean boole = SelectURL(strManage, strYu);
    82.                 if (boole)
    83.                 {
    84.                     arr.Add("<span>此域名可以进行注册</span>");
    85.                 }
    86.                 else
    87.                 {
    88.                     arr.Add("<span style='color:red'>此域名已经注册</span>");
    89.                 }
    90.             }catch(Exception){
    91.                 arr.Add("<span style='color:red'>网络访问失败</span>");
    92.             }
    93.            }
    94.         return arr;
    95.     }
    96.    /// <summary>
    97.    /// 得到服务器返回的信息 进行比较
    98.    /// </summary>
    99.    /// <param name="strManage">服务器返回的信息</param>
    100.    /// <param name="houZui">根据后缀进行比较</param>
    101.    /// <returns>域名是否可用</returns>
    102.     protected Boolean SelectURL(string strManage, string houZui)
    103.     {
    104.         Boolean falge = false;
    105.        
    106.         String Pattern="";
    107.         RegexOptions regex = new RegexOptions();
    108.       
    109.         switch (houZui)
    110.         {
    111.             case ".cn"//cn返回的信息
    112.                 if (strManage == "no matching record")
    113.                 {
    114.                     falge = true;
    115.                 };
    116.                 break;
    117.             case ".com":  //com返回的信息  Net返回的信息 cc返回的信息
    118.                Pattern="No match";
    119.                MatchCollection Matches1 = Regex.Matches(strManage, Pattern, regex);
    120.                foreach (Match NextMatch in Matches1)
    121.                {
    122.                    falge = true;
    123.                }
    124.                break;
    125.                 
    126.             case ".net":
    127.                 Pattern = "No match";
    128.                 MatchCollection Matchess2 = Regex.Matches(strManage, Pattern, regex);
    129.                 foreach (Match NextMatch in Matchess2)
    130.                 {
    131.                     falge = true;
    132.                 }
    133.                 break;
    134.             case ".tv":
    135.                 Pattern = "No match";
    136.                 MatchCollection Matchess6 = Regex.Matches(strManage, Pattern, regex);
    137.                 foreach (Match NextMatch in Matchess6)
    138.                 {
    139.                     falge = true;
    140.                 }
    141.                 break;
    142.             case ".name":
    143.                 Pattern = "No match";
    144.                 MatchCollection Matchess7 = Regex.Matches(strManage, Pattern, regex);
    145.                 foreach (Match NextMatch in Matchess7)
    146.                 {
    147.                     falge = true;
    148.                 }
    149.                 break;
    150.             case ".cc":
    151.                 Pattern = "No match";
    152.                 MatchCollection Matchess3 = Regex.Matches(strManage, Pattern, regex);
    153.                 foreach (Match NextMatch in Matchess3)
    154.                 {
    155.                     falge = true;
    156.                 }
    157.                 break;
    158.             case ".mobi"://mobi返回的信息 org返回的信息 asia返回的信息
    159.                 if (strManage == "NOT FOUND/n")
    160.                 {
    161.                     falge = true;
    162.                 };
    163.                 break;
    164.             case ".org":
    165.                 if (strManage == "NOT FOUND/n")
    166.                 {
    167.                     falge = true;
    168.                     
    169.                 };
    170.                 break;
    171.             case ".info":
    172.                 if (strManage == "NOT FOUND/n")
    173.                 {
    174.                     falge = true;
    175.                 };
    176.                 break;
    177.             case ".asia":
    178.                 if (strManage == "NOT FOUND/n")
    179.                 {
    180.                     falge = true;
    181.                   };
    182.                 break;
    183.             case ".biz":
    184.                 Pattern = "Not found";//BIZ返回的信息
    185.                 MatchCollection Matchess4 = Regex.Matches(strManage, Pattern, regex);
    186.                 foreach (Match NextMatch in Matchess4)
    187.                 {
    188.                     falge = true;
    189.                 }
    190.                 break;
    191.             case ".hk":
    192.                 Pattern = "Domain Not Found";//hk返回的信息
    193.                 MatchCollection Matchess5 = Regex.Matches(strManage, Pattern, regex);
    194.                 foreach (Match NextMatch in Matchess5)
    195.                 {
    196.                     falge = true;
    197.                 }
    198.                 break;
    199.             case ".com.cn":
    200.                 if (strManage == "no matching record")
    201.                 {
    202.                     falge = true;
    203.                 }
    204.                 break;
    205.             case ".net.cn":
    206.                 if (strManage == "no matching record")
    207.                 {
    208.                     falge = true;
    209.                 }
    210.                 break;
    211.           }
    212.         return falge;
    213.     }
    214. }
  • 相关阅读:
    C# 字符串转为DateTime类型
    多线程的注意事项
    linux 安装中文支持
    发布网站遇到的坑
    配置iis支持json解析,配置ssi
    SEO之图片优化
    SEO之面包屑导航
    SEO之HTML标签
    SEO之优化代码
    SEO之网站内部结构优化
  • 原文地址:https://www.cnblogs.com/dingdingmao/p/3146590.html
Copyright © 2011-2022 走看看