DNS ホスト名または IP アドレスを IPHostEntry インスタンスに解決します。
Public Shared Function Resolve( _
ByVal hostName As String _) As IPHostEntry
[C#]
public static IPHostEntry Resolve(stringhostName);
[C++]
public: static IPHostEntry* Resolve(String* hostName);
[JScript]
public static function Resolve(
hostName : String) : IPHostEntry;
パラメータ
- hostName
DNS スタイルのホスト名、または IP アドレス。
戻り値
hostName で指定するホストについてのアドレス情報を格納する IPHostEntry インスタンス。
例外
| 例外の種類 | 条件 |
|---|---|
| ArgumentNullException | hostName が null 参照 (Visual Basic では Nothing) です。 |
| SocketException | hostName を解決するときにエラーが発生しました。 |
| SecurityException | 呼び出し元に、DNS 情報にアクセスするためのアクセス許可がありません。 |
解説
Resolve メソッドは、DNS サーバーでホスト名または IP アドレスと関連付けられた IP アドレスを照会します。
hostName が複数の IP アドレスと関連付けられた DNS スタイルのホスト名の場合は、そのホスト名に解決された最初の IP アドレスだけが返されます。
使用例
[Visual Basic, C#, C++] Resolve メソッドを使用して、IP アドレスを IPHostEntry インスタンスに解決する例を次に示します。
Public Sub DisplayHostAddress(hostString As [String])
Try
' Call the Resolve method passing a DNS style host name or an IP address in
' dotted-quad notation (for example, "www.contoso.com" or "207.46.131.199") to
' obtain an IPHostEntry instance that contains address information for the
' specified host.
Dim hostInfo As IPHostEntry = Dns.Resolve(hostString)
' Get the IP address list that resolves to the host names contained in the Alias
' property.
Dim address As IPAddress() = hostInfo.AddressList
' Get the alias names of the addresses in the IP address list.
Dim [alias] As [String]() = hostInfo.Aliases
Console.WriteLine(("Host name : " + hostInfo.HostName))
Console.WriteLine(ControlChars.Cr + "Aliases : ")
Dim index As Integer
For index = 0 To [alias].Length - 1
Console.WriteLine([alias](index))
Next index
Console.WriteLine(ControlChars.Cr + "IP Address list :")
For index = 0 To address.Length - 1
Console.WriteLine(address(index))
Next index
Catch e As SocketException
Console.WriteLine("SocketException caught!!!")
Console.WriteLine(("Source : " + e.Source))
Console.WriteLine(("Message : " + e.Message))
Catch e As ArgumentNullException
Console.WriteLine("ArgumentNullException caught!!!")
Console.WriteLine(("Source : " + e.Source))
Console.WriteLine(("Message : " + e.Message))
Catch e As NullReferenceException
Console.WriteLine("NullReferenceException caught!!!")
Console.WriteLine(("Source : " + e.Source))
Console.WriteLine(("Message : " + e.Message))
Catch e As Exception
Console.WriteLine("Exception caught!!!")
Console.WriteLine(("Source : " + e.Source))
Console.WriteLine(("Message : " + e.Message))
End Try
[C#]
try {
IPHostEntry hostInfo = Dns.Resolve(hostString);
// 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("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(NullReferenceException e)
{
Console.WriteLine("NullReferenceException 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);
}
[C++]
try {
IPHostEntry* hostInfo = Dns::Resolve(hostString);
// 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(S"Host name : {0}", hostInfo->HostName);
Console::WriteLine(S"\nAliases : ");
for (int index=0; index < alias->Length; index++) {
Console::WriteLine(alias->Item[index]);
}
Console::WriteLine(S"\nIP Address list :");
for (int index=0; index < address->Length; index++) {
Console::WriteLine(address->Item[index]);
}
} catch (SocketException* e) {
Console::WriteLine(S"SocketException caught!!!");
Console::WriteLine(S"Source : {0}", e->Source);
Console::WriteLine(S"Message : {0}", e->Message);
} catch (ArgumentNullException* e) {
Console::WriteLine(S"ArgumentNullException caught!!!");
Console::WriteLine(S"Source : {0}", e->Source);
Console::WriteLine(S"Message : {0}", e->Message);
} catch (NullReferenceException* e) {
Console::WriteLine(S"NullReferenceException caught!!!");
Console::WriteLine(S"Source : {0}", e->Source);
Console::WriteLine(S"Message : {0}", e->Message);
} catch (Exception* e) {
Console::WriteLine(S"Exception caught!!!");
Console::WriteLine(S"Source : {0}", e->Source);
Console::WriteLine(S"Message : {0}", e->Message);
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン
をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
.NET Framework セキュリティ:
- DnsPermission (DNS にアクセスするために必要なアクセス許可) PermissionState.Unrestricted (関連する列挙体)