本文整理匯總了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);
}
}
}
}