/*
Updated for Beta 2 - 25/06/2001
Compile with:
csc whois.cs
Ed Courtenay
http://www.edcourtenay.co.uk/
*/namespace EdCourtenay.Utils.WhoIs
{
using System;
using System.IO;
using System.Net.Sockets;
using System.Text; public class WhoIs
{
public WhoIs()
{
} public static int Main(string[] args)
{
WhoIs whois = new WhoIs();
String host = "rs.internic.net";
String domainName = "";
if (args.Length < 1 || args.Length > 3)
{
Console.WriteLine("Invalid number of arguments");
whois.displayUsage();
return 1;
}
bool setHost = false;
foreach(String arg in args)
{
if (arg.Equals("-h"))
{
setHost = true;
continue;
}
if (setHost)
{
host = arg;
setHost = false;
continue;
}
domainName = arg + " ";
} if (setHost)
{
Console.WriteLine("No host specified");
whois.displayUsage();
return 2;
} try
{
Console.WriteLine(whois.doLookup(host, domainName));
return 0;
}
catch
{
Console.WriteLine("Error connecting to " + host);
return 3;
}
} private void displayUsage()
{
Console.WriteLine("whois [-h whois-server] domainname");
} private String doLookup(String host, String domainName)
{
// Get the stream
TcpClient tcpc = new TcpClient(host, 43); NetworkStream stream = tcpc.GetStream();
StreamWriter writer = new StreamWriter(stream);
StreamReader reader = new StreamReader(stream); writer.AutoFlush = true;
writer.WriteLine(domainName); return reader.ReadToEnd();
}
}
}
Updated for Beta 2 - 25/06/2001
Compile with:
csc whois.cs
Ed Courtenay
http://www.edcourtenay.co.uk/
*/namespace EdCourtenay.Utils.WhoIs
{
using System;
using System.IO;
using System.Net.Sockets;
using System.Text; public class WhoIs
{
public WhoIs()
{
} public static int Main(string[] args)
{
WhoIs whois = new WhoIs();
String host = "rs.internic.net";
String domainName = "";
if (args.Length < 1 || args.Length > 3)
{
Console.WriteLine("Invalid number of arguments");
whois.displayUsage();
return 1;
}
bool setHost = false;
foreach(String arg in args)
{
if (arg.Equals("-h"))
{
setHost = true;
continue;
}
if (setHost)
{
host = arg;
setHost = false;
continue;
}
domainName = arg + " ";
} if (setHost)
{
Console.WriteLine("No host specified");
whois.displayUsage();
return 2;
} try
{
Console.WriteLine(whois.doLookup(host, domainName));
return 0;
}
catch
{
Console.WriteLine("Error connecting to " + host);
return 3;
}
} private void displayUsage()
{
Console.WriteLine("whois [-h whois-server] domainname");
} private String doLookup(String host, String domainName)
{
// Get the stream
TcpClient tcpc = new TcpClient(host, 43); NetworkStream stream = tcpc.GetStream();
StreamWriter writer = new StreamWriter(stream);
StreamReader reader = new StreamReader(stream); writer.AutoFlush = true;
writer.WriteLine(domainName); return reader.ReadToEnd();
}
}
}
谁能提供分不够再加
<body>
<form method="post" runat="server">
<P>要查询的域名
<asp:textbox id="domainName" runat="server"></asp:textbox><asp:dropdownlist id="extDomainName" runat="server"></asp:dropdownlist><asp:button id="btnCheckDomain" runat="server" Text=" 查 询 "></asp:button><BR>
<FONT face="宋体"></FONT>
</P>
<br>
<br>
Domain name: WWW .
<asp:TextBox id="txtDomain" value="" runat="server" />
<asp:Button id="btnQuery" text="Query!" runat="server" />
<BR>
<HR width="100%">
<BR>
<asp:label id="txtResult" runat="server" />
</form>
</body>
.cs文件:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Text;namespace domain.tools
{
/// <summary>
/// Summary description for queryinternic.
/// </summary>
public class domain : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnCheckDomain;
protected System.Web.UI.WebControls.DropDownList extDomainName;
protected System.Web.UI.WebControls.TextBox txtDomain;
protected System.Web.UI.WebControls.Button btnQuery;
protected System.Web.UI.WebControls.Label txtResult;
protected System.Web.UI.WebControls.TextBox domainName;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
extDomainName.Items.Clear();
extDomainName.Items.Add(".com");
extDomainName.Items.Add(".net");
extDomainName.Items.Add(".org");
extDomainName.Items.Add(".com.cn");
extDomainName.Items.Add(".net.cn");
extDomainName.Items.Add(".org.cn");
}
} private void btnCheckDomain_Click(object sender, System.EventArgs e)
{
TcpClient MyTCP = new TcpClient();
string WhoisServer; if(extDomainName.SelectedItem.Value.Length==4)
{
// WhoisServer="whois.internic.net";
WhoisServer="66.150.5.140";
// WhoisServer="whois.paycenter.com.cn";
// WhoisServer="whois.networksolutions.com";
// WhoisServer="rs.internic.net";
}
else
{
WhoisServer="whois.cnnic.net.cn";
} MyTCP.Connect(WhoisServer,43); string strDomain=domainName.Text + extDomainName.SelectedItem.Value;
strDomain = strDomain + "\r\n"; Response.Write("<B>Query Domain: " + strDomain + "</b>");
Response.Write("<BR><B>Whois Server:" + WhoisServer + "</b>");
Response.Write("<hr>"); Byte[] arrDomain = Encoding.Default.GetBytes(strDomain.ToCharArray());
Stream s = MyTCP.GetStream();
s.Write(arrDomain, 0, strDomain.Length);
StreamReader sr = new StreamReader(MyTCP.GetStream(), Encoding.Default); while (-1 != sr.Peek())
{
Response.Write(sr.ReadLine() + "<br>");
}
MyTCP.Close();
}