с учетом полезных фишек:
MSDN писал(а):Dns.GetHostByAddress -метод [Visual Basic]См. также
Dns - класс | Dns - члены | System.Net - пространство имен | Managed Extensions for C++ Programming
Язык
C#
C++
JScript
Visual Basic
Показать все
Возвращает сведения DNS о хосте для IP-адреса.
Список перегрузки
Создает экземпляр IPHostEntry из указанного IPAddress.
Поддерживается .NET Compact Framework.
[Visual Basic] Overloads Public Shared Function GetHostByAddress(IPAddress) As IPHostEntry
[C#] public static IPHostEntry GetHostByAddress(IPAddress);
[C++] public: static IPHostEntry* GetHostByAddress(IPAddress*);
[JScript] public static function GetHostByAddress(IPAddress) : IPHostEntry;
Создает экземпляр IPHostEntry из IP-адреса.
Поддерживается .NET Compact Framework.
[Visual Basic] Overloads Public Shared Function GetHostByAddress(String) As IPHostEntry
[C#] public static IPHostEntry GetHostByAddress(string);
[C++] public: static IPHostEntry* GetHostByAddress(String*);
[JScript] public static function GetHostByAddress(String) : IPHostEntry;
Пример
[Visual Basic, C#, C++] В следующем примере показано создание IPHostEntry из IPAddress.
[Visual Basic, C#, C++] Примечание. Этот пример иллюстрирует использование одной из перегруженных версий GetHostByAddress. Другие примеры можно найти в разделах, посвященных перегрузке.
[Visual Basic]
Public Sub DisplayHostAddress(IpAddressString As [String])
Try
Dim hostIPAddress As IPAddress = IPAddress.Parse(IpAddressString)
' Call the GetHostByAddress(IPAddress) method, passing an IPAddress object as an argument
' to obtain an IPHostEntry instance, containing address information for the specified host.
Dim hostInfo As IPHostEntry = Dns.GetHostByAddress(hostIPAddress)
' 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 above 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 FormatException
Console.WriteLine("FormatException 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 Exception
Console.WriteLine("Exception caught!!!")
Console.WriteLine(("Source : " + e.Source))
Console.WriteLine(("Message : " + e.Message))
End Try
End Sub 'DisplayHostAddress
MSDN писал(а):Dns.GetHostByName -метод [Visual Basic]См. также
Dns - класс | Dns - члены | System.Net - пространство имен | Dns Members (Visual J# Syntax) | Managed Extensions for C++ Programming
Требования
Платформы: 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
Язык
C#
C++
JScript
Visual Basic
Показать все
Возвращает сведения DNS для указанного DNS-имени хоста.
[Visual Basic]
Public Shared Function GetHostByName( _
ByVal hostName As String _
) As IPHostEntry
[C#]
public static IPHostEntry GetHostByName(
string hostName
);
[C++]
public: static IPHostEntry* GetHostByName(
String* hostName
);
[JScript]
public static function GetHostByName(
hostName : String
) : IPHostEntry;
Параметры
hostName
Строка, содержащая DNS-имя хоста.
Возвращаемое значение
Объект IPHostEntry, содержащий сведения о хосте для адреса, указанного в hostName.
Исключения
Тип исключения Условие
ArgumentNullException Значение параметра hostName — пустая ссылка (Nothing в Visual Basic).
SocketException При преобразовании hostName возникает ошибка.
SecurityException У вызывающего оператора не имеется разрешения на доступ к сведениям DNS.
Примечания
Метод GetHostByName запрашивает у DNS-сервера Интернета сведения о хосте.
Для асинхронного доступа к сведениям DNS используйте методы BeginGetHostByName и EndGetHostByName.
Пример
[Visual Basic, C#, C++] В следующем примере показано применение метода GetHostByName для получения сведений DNS для указанного DNS-имени хоста.
[Visual Basic]
Public Sub DisplayHostName(hostName As [String])
Try
' Call the GetHostByName method, passing a DNS style host name(for example,
' "www.contoso.com") as an argument to obtain an IPHostEntry instance, that
' contains information for the specified host.
Dim hostInfo As IPHostEntry = Dns.GetHostByName(hostName)
' 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 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 Exception
Console.WriteLine("Exception caught!!!")
Console.WriteLine(("Source : " + e.Source))
Console.WriteLine(("Message : " + e.Message))
End Try
[C#]
try
{
IPHostEntry hostInfo = Dns.GetHostByName(hostName);
// 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(Exception e)
{
Console.WriteLine("Exception caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
[C++]
try {
IPHostEntry* hostInfo = Dns::GetHostByName(hostName);
// 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 (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