1 using System;
 2 using System.Net;
 3 
 4 namespace study
 5 {
 6     class IPHostEntrySample
 7     {
 8         public static void func(string argv)
 9         {
10             //获得主机名
11             IPHostEntry results = Dns.GetHostByName(argv);
12             Console.WriteLine("Host:{0}", results.HostName);
13 
14             //使用循环显示IP地址表
15             foreach(string alias in results.Aliases)
16             {
17                 Console.WriteLine("Alias:{0}", alias);
18             }
19 
20             //遍历地址列表
21             foreach(IPAddress address in results.AddressList)
22             {
23                 Console.WriteLine("Address:{0}", address.ToString());
24             }
25         }
26     }
27 }

提供字符串,例如IPHostEntrySample.func("www.qq.com"),返回目标主机信息

注:控制台版本

相关文章:

  • 2021-12-04
  • 2021-12-04
  • 2021-11-17
  • 2021-09-20
  • 2022-02-24
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-21
  • 2021-08-15
  • 2022-12-23
  • 2022-03-04
  • 2022-12-23
  • 2021-12-29
  • 2021-12-19
相关资源
相似解决方案