获取域名的 WhoIs 详细信息

发布于 2024-08-10 03:16:52 字数 4574 浏览 4 评论 0原文

当我搜索域检查器的开源时,我得到了此参考 http://www. codeproject.com/KB/aspnet/DataScraping.aspx 实际上它是在 vb.net 中,我将其转换为 C# 代码并将代码粘贴到我的网页中,我发送了全部源代码和代码

源代码

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
        <TABLE id="Table1" cellSpacing="0" cellPadding="0" width="358" border="0">
            <TR>
            <TD>
                <asp:Label id="Label2" Runat="server">www.</asp:Label>
                <asp:TextBox id="txtDomain" Runat="server">
                Check Domain</asp:TextBox></TD>
            <TD>
                <asp:Button id="btnQuery" Text="Check Domain" Runat="server" OnClick="btnQuery_Click1">
                </asp:Button></TD>
        </TR>
        <TR>
            <TD>
                <asp:Label id="txtResult" Runat="server"></asp:Label></TD>
            <TD></TD>
        </TR>
        </TABLE>
        </form>
    </body>

</html>

C# 代码

//code


using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Sockets;
using System.Text;
using System.IO;

using System.Net;
using System.Text.RegularExpressions;

public partial class _Default : System.Web.UI.Page
{
    //protected System.Web.UI.WebControls.Label Label1;
    //protected System.Web.UI.WebControls.Button btnQuery;
    //protected System.Web.UI.WebControls.Label txtResult;
    //protected System.Web.UI.WebControls.Label Label2;
    //protected System.Web.UI.WebControls.TextBox txtDomain;

    protected void Page_Load(object sender, EventArgs e)
    {
        txtDomain.Attributes.Add("onclick", "this.value='';");
    }

    private void btnQuery_Click(System.Object sender, System.EventArgs e)
    {
        // Stores the bufData extracted from the webclient 

        string firstLevelbufData = null;
        try
        {
            // similarly we can select any server address for bufData mining

            string strURL = "http://www.directnic.com/whois/index.php?query=" + txtDomain.Text;
            WebClient web = new WebClient();
            // byte array to store the extracted bufData by webclient

            byte[] bufData = null;
            bufData = web.DownloadData(strURL);
            // got the bufData now convert it into string form

            firstLevelbufData = Encoding.Default.GetString(bufData);
        }
        catch (System.Net.WebException ex)
        {
            // this exception will be fired when the host name

            // is not resolved or any other connection problem

            txtResult.Text = ex.Message;
            return;
        }
        try
        {
            // first and last are the regular expression string

            // for extraction bufData witnin two tags

            // you can change according to your requirement

            string first = null;
            string last = null;

            first = "<p class= " + Strings.Chr(34) + "text12" + Strings.Chr(34) + ">";
             last = "</p>";
             Regex RE = new Regex(first + "(?<MYDATA>.*?(?=" + last + "))", RegexOptions.IgnoreCase | RegexOptions.Singleline);
             // try to extract the bufData within the first and last tag

            Match m = RE.Match(firstLevelbufData);
            // got the result

             txtResult.Text = m.Groups("MYDATA").Value + "";
             // check if no information abour that domain is available

             if (txtResult.Text.Length < 10) txtResult.Text = "Information about this domain is not available !!";
         }
          catch (Exception e3)
          {
             txtResult.Text = "Sorry the whois information" + " is currently not available !!";
          }
    }

}

但我在第 70 行出现错误“(first =” “;)” 以及第 78 页 如果您想要原始的 vb 代码,这是参考,请查看

http: //www.codeproject.com/KB/aspnet/DataScraping.aspx

when i search for open source for domain checker, i got this reference http://www.codeproject.com/KB/aspnet/DataScraping.aspx
actually it is in vb.net i convert into c# code and paste the code in my web page i sending total source and code

source code

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
        <TABLE id="Table1" cellSpacing="0" cellPadding="0" width="358" border="0">
            <TR>
            <TD>
                <asp:Label id="Label2" Runat="server">www.</asp:Label>
                <asp:TextBox id="txtDomain" Runat="server">
                Check Domain</asp:TextBox></TD>
            <TD>
                <asp:Button id="btnQuery" Text="Check Domain" Runat="server" OnClick="btnQuery_Click1">
                </asp:Button></TD>
        </TR>
        <TR>
            <TD>
                <asp:Label id="txtResult" Runat="server"></asp:Label></TD>
            <TD></TD>
        </TR>
        </TABLE>
        </form>
    </body>

</html>

C# Code

//code


using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Sockets;
using System.Text;
using System.IO;

using System.Net;
using System.Text.RegularExpressions;

public partial class _Default : System.Web.UI.Page
{
    //protected System.Web.UI.WebControls.Label Label1;
    //protected System.Web.UI.WebControls.Button btnQuery;
    //protected System.Web.UI.WebControls.Label txtResult;
    //protected System.Web.UI.WebControls.Label Label2;
    //protected System.Web.UI.WebControls.TextBox txtDomain;

    protected void Page_Load(object sender, EventArgs e)
    {
        txtDomain.Attributes.Add("onclick", "this.value='';");
    }

    private void btnQuery_Click(System.Object sender, System.EventArgs e)
    {
        // Stores the bufData extracted from the webclient 

        string firstLevelbufData = null;
        try
        {
            // similarly we can select any server address for bufData mining

            string strURL = "http://www.directnic.com/whois/index.php?query=" + txtDomain.Text;
            WebClient web = new WebClient();
            // byte array to store the extracted bufData by webclient

            byte[] bufData = null;
            bufData = web.DownloadData(strURL);
            // got the bufData now convert it into string form

            firstLevelbufData = Encoding.Default.GetString(bufData);
        }
        catch (System.Net.WebException ex)
        {
            // this exception will be fired when the host name

            // is not resolved or any other connection problem

            txtResult.Text = ex.Message;
            return;
        }
        try
        {
            // first and last are the regular expression string

            // for extraction bufData witnin two tags

            // you can change according to your requirement

            string first = null;
            string last = null;

            first = "<p class= " + Strings.Chr(34) + "text12" + Strings.Chr(34) + ">";
             last = "</p>";
             Regex RE = new Regex(first + "(?<MYDATA>.*?(?=" + last + "))", RegexOptions.IgnoreCase | RegexOptions.Singleline);
             // try to extract the bufData within the first and last tag

            Match m = RE.Match(firstLevelbufData);
            // got the result

             txtResult.Text = m.Groups("MYDATA").Value + "";
             // check if no information abour that domain is available

             if (txtResult.Text.Length < 10) txtResult.Text = "Information about this domain is not available !!";
         }
          catch (Exception e3)
          {
             txtResult.Text = "Sorry the whois information" + " is currently not available !!";
          }
    }

}

but i am getting error at line 70 "(first = "";)"
and at page 78
help be if you want the original vb code this is the reference check out

http://www.codeproject.com/KB/aspnet/DataScraping.aspx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Bonjour°[大白 2024-08-17 03:16:52
using System.Net.Sockets;
using System.Text;
using System.IO;
using System.Collections;
using System.Net;
using System.Text.RegularExpressions;


public partial class WhoIsC : System.Web.UI.Page
{

    #region " Web Form Designer Generated Code "

    //This call is required by the Web Form Designer.
    [System.Diagnostics.DebuggerStepThrough()]
    private void InitializeComponent()
    {

    }

    protected void  // ERROR: Handles clauses are not supported in C#
Page_Init(System.Object sender, System.EventArgs e)
    {
        //CODEGEN: This method call is required by the Web Form Designer
        //Do not modify it using the code editor.
        InitializeComponent();
    }

    #endregion

    private void  // ERROR: Handles clauses are not supported in C#
Page_Load(System.Object sender, System.EventArgs e)
    {
        // Adds the java script code for clearing  the existing text from the text box when user wants to
        // enter a new domain name
        txtDomain.Attributes.Add("onclick", "this.value='';");
    }

    public  void  // ERROR: Handles clauses are not supported in C#
btnQuery_Click(System.Object sender, System.EventArgs e)
    {
        string firstLevelbufData = null;
        // Stores the bufData extracted from the webclient 
        try
        {
            // similarly we can select any server address for bufData mining
            string strURL = "http://www.directnic.com/whois/index.php?query=" + txtDomain.Text;
            WebClient web = new WebClient();
            // byte array to store the extracted bufData by webclient
            byte[] bufData = null;
            bufData = web.DownloadData(strURL);
            // got the bufData now convert it into string form
            firstLevelbufData = Encoding.Default.GetString(bufData);
        }
        catch (System.Net.WebException ex)
        {
            // this exception will be fired when the host name is not resolved or any other connection problem
            txtResult.Text = ex.Message.ToString();
            return;
        }
        try
        {
            // first and last are the regular expression string for extraction bufData witnin two tags
            // you can change according to your requirement
            string first = null;
            string last = null;
            // chr(34) is used for (") symbol
            first = "<p class=\"text12\">";
            last = "</p>";

            Regex RE = new Regex(first + "(?<MYDATA>.*?(?=" + last + "))", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            // try to extract the bufData  within the first and last tag
            Match m = RE.Match(firstLevelbufData);
            // got the result
            txtResult.Text = m.Groups["MYDATA"].Value + "<br>";
            // check if no information abour that domain is available
            if (txtResult.Text.Length < 10) txtResult.Text = "Information about this domain is not available !!";
        }
        catch (System.Net.WebException ex)
        {
            txtResult.Text = "Sorry the whois information is currently not available !!";
        }
    }

}
using System.Net.Sockets;
using System.Text;
using System.IO;
using System.Collections;
using System.Net;
using System.Text.RegularExpressions;


public partial class WhoIsC : System.Web.UI.Page
{

    #region " Web Form Designer Generated Code "

    //This call is required by the Web Form Designer.
    [System.Diagnostics.DebuggerStepThrough()]
    private void InitializeComponent()
    {

    }

    protected void  // ERROR: Handles clauses are not supported in C#
Page_Init(System.Object sender, System.EventArgs e)
    {
        //CODEGEN: This method call is required by the Web Form Designer
        //Do not modify it using the code editor.
        InitializeComponent();
    }

    #endregion

    private void  // ERROR: Handles clauses are not supported in C#
Page_Load(System.Object sender, System.EventArgs e)
    {
        // Adds the java script code for clearing  the existing text from the text box when user wants to
        // enter a new domain name
        txtDomain.Attributes.Add("onclick", "this.value='';");
    }

    public  void  // ERROR: Handles clauses are not supported in C#
btnQuery_Click(System.Object sender, System.EventArgs e)
    {
        string firstLevelbufData = null;
        // Stores the bufData extracted from the webclient 
        try
        {
            // similarly we can select any server address for bufData mining
            string strURL = "http://www.directnic.com/whois/index.php?query=" + txtDomain.Text;
            WebClient web = new WebClient();
            // byte array to store the extracted bufData by webclient
            byte[] bufData = null;
            bufData = web.DownloadData(strURL);
            // got the bufData now convert it into string form
            firstLevelbufData = Encoding.Default.GetString(bufData);
        }
        catch (System.Net.WebException ex)
        {
            // this exception will be fired when the host name is not resolved or any other connection problem
            txtResult.Text = ex.Message.ToString();
            return;
        }
        try
        {
            // first and last are the regular expression string for extraction bufData witnin two tags
            // you can change according to your requirement
            string first = null;
            string last = null;
            // chr(34) is used for (") symbol
            first = "<p class=\"text12\">";
            last = "</p>";

            Regex RE = new Regex(first + "(?<MYDATA>.*?(?=" + last + "))", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            // try to extract the bufData  within the first and last tag
            Match m = RE.Match(firstLevelbufData);
            // got the result
            txtResult.Text = m.Groups["MYDATA"].Value + "<br>";
            // check if no information abour that domain is available
            if (txtResult.Text.Length < 10) txtResult.Text = "Information about this domain is not available !!";
        }
        catch (System.Net.WebException ex)
        {
            txtResult.Text = "Sorry the whois information is currently not available !!";
        }
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文