• [Visual C#] Whois域名查询协议实现


     1 using System;
     2 using System.Collections.Generic;
     3 using System.Text;
     4 using System.IO;
     5 using System.Net;
     6 using System.Net.Sockets;
     7 
     8 namespace ConsoleApplication1
     9 {
    10     class Program
    11     {
    12         static void Main(string[] args)
    13         {
    14             // 参数一:待查询的域名
    15             // 参数二:WHOIS服务器
    16             // 参数三:WHOIS端口
    17 
    18             TcpClient tcpClient = new TcpClient();                                          // 初始化新的TCPCLIENT实例
    19                 
    20             tcpClient.Connect(args[1], Int32.Parse(args[2]));                               // 连接 Whois Server
    21 
    22             tcpClient.SendBufferSize = 1024;                                                // 设置发送缓冲大小
    23 
    24             tcpClient.ReceiveBufferSize = 2048;                                             // 设置接收缓冲大小
    25 
    26             byte[] sendByte = Encoding.Default.GetBytes(string.Format("{0}\n", args[0]));   // 转换发送请求的报文
    27 
    28             tcpClient.Client.Send(sendByte);                                                // 发送查询请求
    29 
    30             string strReceive = string.Empty;                                               // 初始化一个接收查询结果字符串
    31 
    32             byte[] receiveByte = new byte[2048];                                            // 初始化一接收数据数组
    33 
    34             while (tcpClient.Client.Receive(receiveByte) > 0)
    35                 strReceive += Encoding.Default.GetString(receiveByte);                      // 接收查询结果
    36 
    37             strReceive = strReceive.Replace("\n""\r\n");                                  // 把Unix换行符转换为Windows换行符
    38 
    39             Console.WriteLine(strReceive);                                                  // 输出结果
    40         }
    41     }
    42 }
  • 相关阅读:
    2019.8.15刷题统计
    2019.8.12刷题统计
    2019.8.11刷题统计
    2019.8.10刷题统计
    2019.8.9刷题统计
    2019.8.8刷题统计
    2019.8.7刷题统计
    2019.8.6刷题统计
    xuezhan.org 6.28
    xuezhan.org 6.27
  • 原文地址:https://www.cnblogs.com/briny/p/2382909.html
Copyright © 2020-2023  润新知