C# .NET 域名 Whois 查询代码

Whois 简单来说,就是一个用来查询域名是否已经被注册,以及注册域名的详细信息的数据库(如域名所有人、域名注册商、域名注册日期和过期日期等)。通过域名Whois服务器查询,可以查询域名归属者联系方式,以及注册和到期时间。

以下为 C# 域名 Whois 查询代码

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.GetHostEntry(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;
}

调用事例:

[TestMethod]
public void TestWhoisMethod()
{
	string whois = Whois("24kplus.com");
	Debug.WriteLine(whois);
	Console.ReadKey();
}

结果:

   Server Name: 24KPLUS.COM
   IP Address: 34.92.152.179
   Registrar: DNSPod, Inc.
   Registrar WHOIS Server: whois.dnspod.com
   Registrar URL: http://www.dnspod.cn

   Domain Name: 24KPLUS.COM
   Registry Domain ID: 2377863045_DOMAIN_COM-VRSN
   Registrar WHOIS Server: whois.dnspod.com
   Registrar URL: http://www.dnspod.cn
   Updated Date: 2019-07-05T12:32:38Z
   Creation Date: 2019-04-08T03:16:41Z
   Registry Expiry Date: 2023-04-08T03:16:41Z
   Registrar: DNSPod, Inc.
   Registrar IANA ID: 1697
   Registrar Abuse Contact Email: abuse@dnspod.com
   Registrar Abuse Contact Phone: +86.95716
   Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
   Name Server: F1G1NS1.DNSPOD.NET
   Name Server: F1G1NS2.DNSPOD.NET
   DNSSEC: unsigned
   URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/
>>> Last update of whois database: 2019-08-25T11:21:50Z <<<

For more information on Whois status codes, please visit https://icann.org/epp

NOTICE: The expiration date displayed in this record is the date the
registrar's sponsorship of the domain name registration in the registry is
currently set to expire. This date does not necessarily reflect the expiration
date of the domain name registrant's agreement with the sponsoring
registrar.  Users may consult the sponsoring registrar's Whois database to
view the registrar's reported date of expiration for this registration.

TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume and
automated except as reasonably necessary to register domain names or
modify existing registrations; the Data in VeriSign Global Registry
Services' ("VeriSign") Whois database is provided by VeriSign for
information purposes only, and to assist persons in obtaining information
about or related to a domain name registration record. VeriSign does not
guarantee its accuracy. By submitting a Whois query, you agree to abide
by the following terms of use: You agree that you may use this Data only
for lawful purposes and that under no circumstances will you use this Data
to: (1) allow, enable, or otherwise support the transmission of mass
unsolicited, commercial advertising or solicitations via e-mail, telephone,
or facsimile; or (2) enable high volume, automated, electronic processes
that apply to VeriSign (or its computer systems). The compilation,
repackaging, dissemination or other use of this Data is expressly
prohibited without the prior written consent of VeriSign. You agree not to
use electronic processes that are automated and high-volume to access or
query the Whois database except as reasonably necessary to register
domain names or modify existing registrations. VeriSign reserves the right
to restrict your access to the Whois database in its sole discretion to ensure
operational stability.  VeriSign may restrict or terminate your access to the
Whois database for failure to abide by these terms of use. VeriSign
reserves the right to modify these terms at any time.

The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars.
—— 完 ——
相关推荐
评论

立 为 非 似

中 谁 昨 此

宵 风 夜 星

。 露 , 辰

文章点击榜

细 无 轻 自

如 边 似 在

愁 丝 梦 飞

。 雨 , 花