program.cs

来自「里面包括很多网络的模拟 有一个网页下载工具 基于控制台」· CS 代码 · 共 61 行

CS
61
字号
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;


namespace GetHostByName
{
    
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                IPHostEntry hostInfo = Dns.GetHostByName(args[0]);
                // Get the IP address list that resolves to the host names contained in the 
                // Alias property.
                IPAddress[] address = hostInfo.AddressList;
                // Get the alias names of the addresses in the IP address list.
                String[] alias = hostInfo.Aliases;

                Console.WriteLine("Canonical host name : " + hostInfo.HostName);
                Console.WriteLine("\nAliases : ");
                for (int index = 0; index < alias.Length; index++)
                {
                    Console.WriteLine(alias[index]);
                }
                Console.WriteLine("\nIP address list : ");
                for (int index = 0; index < address.Length; index++)
                {
                    Console.WriteLine(address[index]);
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("SocketException caught!!!");
                Console.WriteLine("Source : " + e.Source);
                Console.WriteLine("Message : " + e.Message);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine("ArgumentNullException caught!!!");
                Console.WriteLine("Source : " + e.Source);
                Console.WriteLine("Message : " + e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught!!!");
                Console.WriteLine("Source : " + e.Source);
                Console.WriteLine("Message : " + e.Message);
            }
            Console.ReadKey();

        }
    }
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?