|
楼主 |
发表于 2013-7-9 15:10:57
|
显示全部楼层
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.Resolve(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.UTF8.GetString(buffer, 0, recv);
recv = s.Receive(buffer);
}
s.Shutdown(SocketShutdown.Both);
}
catch
{
throw new SocketException();
}
finally
{
if (s != null)
s.Close();
}
return ret;
}
这个代码在网上可以查到的,公开吧,也不算什么公司机密,去研究百度指数了
|
|