VB.Net by API/System.Net/Dns
Содержание
Dns.BeginResolve
<source lang="vbnet"> Imports System.Net Imports System.Net.Sockets
Public Class Tester
Public Shared Sub Main Dim myThread As Threading.Thread myThread = New Threading.Thread(AddressOf BeginResolveIP) myThread.Start() End Sub Private Shared Sub BeginResolveIP() Try Dim myAsyncCallback As New AsyncCallback(AddressOf GetIPList)
Dim myIAsyncResult As IAsyncResult = Dns.BeginResolve("www.google.ru", myAsyncCallback, Nothing) Do While Not myIAsyncResult.IsCompleted Threading.Thread.Sleep(10) Loop Threading.Thread.Sleep(2000) Catch ex As SocketException Console.WriteLine(ex.Message) End Try End Sub Private Shared Sub GetIPList(ByVal pIAsyncResult As IAsyncResult) Dim myIPHostEntry As IPHostEntry myIPHostEntry = Dns.EndResolve(pIAsyncResult) Dim myIPAddresses() As IPAddress = myIPHostEntry.AddressList Dim myIPAddress As IPAddress For Each myIPAddress In myIPAddresses Console.WriteLine(myIPAddress.ToString) Next End Sub
End Class
</source>
Dns.GetHostByAddress
<source lang="vbnet"> Imports System.Net Imports System.Net.Sockets
Public Class Tester
Public Shared Sub Main Dim strHostName As String Try strHostName = Dns.GetHostByAddress("68.129.2.123").HostName Console.WriteLine(strHostName) Catch exfe As FormatException Console.WriteLine(exfe.Message) Catch exse As SocketException Console.WriteLine(exse.Message) End Try End Sub
End Class
</source>
Dns.GetHostByName
<source lang="vbnet">
Imports System.Environment Imports System.Net
Public Class Tester
Public Shared Sub Main Dim hostname As String = Dns.GetHostName() Dim ipaddress As String = CType(Dns.GetHostByName(hostname).AddressList.GetValue(0), IPAddress).ToString Console.WriteLine("Computer Name: " & hostname & " IP Address: " & ipaddress) End Sub
End Class
</source>
Dns.GetHostName()
<source lang="vbnet">
Imports System.Environment
Imports System.Net
Public Class Tester
Public Shared Sub Main Dim hostname As String = Dns.GetHostName() Dim ipaddress As String = CType(Dns.GetHostByName(hostname).AddressList.GetValue(0), IPAddress).ToString Console.WriteLine("Computer Name: " & hostname & " IP Address: " & ipaddress) End Sub
End Class
</source>
Dns.Resolve
<source lang="vbnet"> Imports System.Net Imports System.Net.Sockets
Public Class Tester
Public Shared Sub Main
Try Dim myIPHostEntry As IPHostEntry = Dns.Resolve("www.google.ru") Dim myIPAddresses() As IPAddress = myIPHostEntry.AddressList Dim myIPAddress As IPAddress Dim strIPAddressList As String For Each myIPAddress In myIPAddresses Console.WriteLine(myIPAddress.ToString) Next Catch ex As SocketException Console.WriteLine(ex.Message) End Try End Sub
End Class
</source>