-
域名查询源码
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.Collections;
- using System.Text.RegularExpressions;
- public class SelectYuMing
- {
- public SelectYuMing()
- {
-
-
-
- }
-
-
-
-
-
-
- public static string Whois(string domain)
- {
- if (domain == null)
- throw new ArgumentNullException();
- int ccStart = domain.LastIndexOf(".");
- if (ccStart < 0 || ccStart == domain.Length)
- throw new ArgumentException();
- string ret = "";
- Socket s = null;
- try
- {
- string cc = domain.Substring(ccStart + 1);
- s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- s.Connect(new IPEndPoint(Dns.Resolve(cc + ".whois-servers.net").AddressList[0], 43));
- s.Send(Encoding.ASCII.GetBytes(domain + "/r/n"));
- byte[] buffer = new byte[1024];
- int recv = s.Receive(buffer);
- while (recv > 0)
- {
- ret += Encoding.ASCII.GetString(buffer, 0, recv);
- recv = s.Receive(buffer);
- }
- s.Shutdown(SocketShutdown.Both);
- }
- catch
- {
- throw new SocketException();
- }
- finally
- {
- if (s != null)
- s.Close();
- }
- return ret;
- }
-
-
-
-
-
-
- public ArrayList SelectYu(ArrayList str,string strYuMing)
- {
- ArrayList arr=new ArrayList();
- foreach(string strYu in str)
- {
- try
- {
- string strManage = Whois(strYuMing + strYu);
- Boolean boole = SelectURL(strManage, strYu);
- if (boole)
- {
- arr.Add("<span>此域名可以进行注册</span>");
- }
- else
- {
- arr.Add("<span style='color:red'>此域名已经注册</span>");
- }
- }catch(Exception){
- arr.Add("<span style='color:red'>网络访问失败</span>");
- }
- }
- return arr;
- }
-
-
-
-
-
-
- protected Boolean SelectURL(string strManage, string houZui)
- {
- Boolean falge = false;
-
- String Pattern="";
- RegexOptions regex = new RegexOptions();
-
- switch (houZui)
- {
- case ".cn":
- if (strManage == "no matching record")
- {
- falge = true;
- };
- break;
- case ".com":
- Pattern="No match";
- MatchCollection Matches1 = Regex.Matches(strManage, Pattern, regex);
- foreach (Match NextMatch in Matches1)
- {
- falge = true;
- }
- break;
-
- case ".net":
- Pattern = "No match";
- MatchCollection Matchess2 = Regex.Matches(strManage, Pattern, regex);
- foreach (Match NextMatch in Matchess2)
- {
- falge = true;
- }
- break;
- case ".tv":
- Pattern = "No match";
- MatchCollection Matchess6 = Regex.Matches(strManage, Pattern, regex);
- foreach (Match NextMatch in Matchess6)
- {
- falge = true;
- }
- break;
- case ".name":
- Pattern = "No match";
- MatchCollection Matchess7 = Regex.Matches(strManage, Pattern, regex);
- foreach (Match NextMatch in Matchess7)
- {
- falge = true;
- }
- break;
- case ".cc":
- Pattern = "No match";
- MatchCollection Matchess3 = Regex.Matches(strManage, Pattern, regex);
- foreach (Match NextMatch in Matchess3)
- {
- falge = true;
- }
- break;
- case ".mobi":
- if (strManage == "NOT FOUND/n")
- {
- falge = true;
- };
- break;
- case ".org":
- if (strManage == "NOT FOUND/n")
- {
- falge = true;
-
- };
- break;
- case ".info":
- if (strManage == "NOT FOUND/n")
- {
- falge = true;
- };
- break;
- case ".asia":
- if (strManage == "NOT FOUND/n")
- {
- falge = true;
- };
- break;
- case ".biz":
- Pattern = "Not found";
- MatchCollection Matchess4 = Regex.Matches(strManage, Pattern, regex);
- foreach (Match NextMatch in Matchess4)
- {
- falge = true;
- }
- break;
- case ".hk":
- Pattern = "Domain Not Found";
- MatchCollection Matchess5 = Regex.Matches(strManage, Pattern, regex);
- foreach (Match NextMatch in Matchess5)
- {
- falge = true;
- }
- break;
- case ".com.cn":
- if (strManage == "no matching record")
- {
- falge = true;
- }
- break;
- case ".net.cn":
- if (strManage == "no matching record")
- {
- falge = true;
- }
- break;
- }
- return falge;
- }
- }
-
相关阅读:
软工实践个人总结
第02组 Beta版本演示
第02组 Beta冲刺(5/5)
第02组 Beta冲刺(4/5)
第02组 Beta冲刺(3/5)
第02组 Beta冲刺(2/5)
第02组 Beta冲刺(1/5)
第02组 Alpha事后诸葛亮
第02组 Alpha冲刺(6/6)
第02组 Alpha冲刺(5/6)
-
原文地址:https://www.cnblogs.com/dingdingmao/p/3146590.html
Copyright © 2020-2023
润新知