本文整理汇总了C#中System.Net.Dns.GetHostEntry方法的典型用法代码示例。如果您正苦于以下问题:C# Dns.GetHostEntry方法的具体用法?C# Dns.GetHostEntry怎么用?C# Dns.GetHostEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Dns.GetHostEntry方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoGetHostEntry
public static void DoGetHostEntry(IPAddress address)
{
IPHostEntry host = Dns.GetHostEntry(address);
Console.WriteLine($"GetHostEntry({address}) returns HostName: {host.HostName}");
}
示例2: DoGetHostEntry
public static void DoGetHostEntry(string hostname)
{
IPHostEntry host = Dns.GetHostEntry(hostname);
Console.WriteLine($"GetHostEntry({hostname}) returns:");
foreach (IPAddress address in host.AddressList)
{
Console.WriteLine($" {address}");
}
}
示例3: Dns.GetHostEntry(String value)
//引入命名空间
using System;
using System.Net;
class MainClass
{
public static void Main(string[] args)
{
foreach (string comp in args)
{
try
{
IPAddress[] addresses = Dns.GetHostEntry(comp).AddressList;
foreach (IPAddress address in addresses)
{
Console.WriteLine("{0} = {1} ({2})",
comp, address, address.AddressFamily);
}
}
catch (Exception ex)
{
Console.WriteLine("{0} = Error ({1})", comp, ex.Message);
}
}
}
}