zoukankan      html  css  js  c++  java
  • [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 }
  • 相关阅读:
    解决 Mac launchpad 启动台 Gitter 图标无法删除的问题
    React 与 React-Native 使用同一个 meteor 后台
    解决 React-Native mac 运行报错 error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by ope
    一行命令更新所有 npm 依赖包
    swift学习笔记
    IOS语言总结
    focusSNS学习笔记
    别小看锤子,老罗真的很认真
    windowsphone开发页面跳转到另一个dll中的页面
    【令人振奋】【转】微软潘正磊谈DevOps、Visual Studio 2013新功能、.NET未来
  • 原文地址:https://www.cnblogs.com/briny/p/2382909.html
Copyright © 2011-2022 走看看