我正在尝试使用简单的代码来执行whois查找。我正在使用2个库
获取IP地址:https://github.com/MichaCo/DnsClient.NET
建立套接字连接:https://github.com/nterry/AwesomeSockets
我刚刚结合了基本的例子。
这是我的代码:
using AwesomeSockets.Buffers;
using AwesomeSockets.Domain.Sockets;
using AwesomeSockets.Sockets;
using DnsClient;
using System;
using System.Linq;
using System.Net;
namespace WhoisSocket
{
class Program
{
static void Main(string[] args)
{
var lookup = new LookupClient();
var result = lookup.QueryAsync("whois.verisign-grs.com", QueryType.ANY).Result;
var record = result.Answers.ARecords().FirstOrDefault();
var address = record?.Address;
//Client-side code
ISocket server = AweSock.TcpConnect(address.ToString(), 43);
AwesomeSockets.Buffers.Buffer inBuf = AwesomeSockets.Buffers.Buffer.New();
AwesomeSockets.Buffers.Buffer outBuf = AwesomeSockets.Buffers.Buffer.New();
//Lets send some data to the server! Make a Buffer object and populate it with some data like so:
AwesomeSockets.Buffers.Buffer.ClearBuffer(outBuf);
AwesomeSockets.Buffers.Buffer.Add(outBuf, "google.com"); // i also tried with \r\n
AwesomeSockets.Buffers.Buffer.FinalizeBuffer(outBuf);
//Now lets send it to the server!
int bytesSent = AweSock.SendMessage(server, outBuf);
//And receive any inbound messages as well. Received datga will be stored in inBuf.
Tuple<int, EndPoint> received = AweSock.ReceiveMessage(server, inBuf);
var test = received.Item2.ToString();
server.Close();
Console.WriteLine(test);
}
}
}
在received
中,没有预期的数据。我手动使用telnet连接和发送域,它工作正常,所以我一定做错了,但我看不出它是什么。