背景
今天我想测试一下WHOIS查询和响应协议是如何工作的,我阅读了一些关于 Wiki 的信息并开始编写代码。5 分钟后,我有了完整且可工作的代码,但我有一些问题想与您分享。
代码
这是一个简单的代码,它向给定的whois.iana.org url 发出请求并从中获取回复。例如,在这里我向vitobrothersoft.com提出请求并得到回复。现在主要问题不是这一切是如何运作的,这对我来说是可以理解的。在测试这部分代码时,我更改了请求域whois.iana.org、com.whois-servers.net、whois.verisign-grs.com并且在某些方面答复在某些方面是相同的。您可以在下面查看回复示例。
#include "stdafx.h"
using namespace System;
#define PORT 43
int main(array<System::String ^> ^args)
{
System::Net::Sockets::TcpClient^ client = gcnew System::Net::Sockets::TcpClient("whois.iana.org", PORT);
if( client != nullptr ) {
System::String^ formatedDomain = "vitobrothersoft.com" + "\r\n";
System::Text::Encoding^ ascii = System::Text::Encoding::ASCII;
array<System::Byte>^ byteUrl = ascii->GetBytes(formatedDomain);
System::IO::Stream^ stream = client->GetStream();
// Write formatted URL to stream.
stream->Write( byteUrl, 0, formatedDomain->Length );
System::IO::StreamReader^ streamReader = gcnew System::IO::StreamReader( stream, System::Text::Encoding::ASCII );
Console::Write( streamReader->ReadToEnd( ) );
}
}
回复示例
[Querying com.whois-servers.net]
[com.whois-servers.net]
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
Domain Name: EXAMPLE.COM
Registrar: RESERVED-INTERNET ASSIGNED NUMBERS AUTHORITY
Whois Server: whois.iana.org
Referral URL: http://res-dom.iana.org
Name Server: A.IANA-SERVERS.NET
Name Server: B.IANA-SERVERS.NET
Status: clientDeleteProhibited
Status: clientTransferProhibited
Status: clientUpdateProhibited
Updated Date: 26-mar-2004
Creation Date: 14-aug-1995
Expiration Date: 13-aug-2011
>>> Last update of whois database: Tue, 17 Aug 2010 02:23:52 UTC <<<
问题
我想知道
- 不同服务(网址)之间有什么区别?
- Status (clientDeleteProhibited, clientTransferProhibited, clientUpdateProhibited) 可以有多少个值?
- 我需要有关回复文本每个字段的完整信息