VB.Net Tutorial/Socket Network/IPHostEntry

Материал из VB Эксперт
Перейти к: навигация, поиск

Get Address List from IPHostEntry

Imports System.Net
Imports System.Net.Sockets

Public Class Tester
    Public Shared Sub Main
        Dim hostEntry As IPHostEntry
        Dim addrList As IPAddress()
        Dim i As Integer
        Dim strTemp As String
    
        Try
          hostEntry = Dns.Resolve("68.178.206.138")
    
          addrList = hostEntry.AddressList
    
          For i = 0 To addrList.Length - 1
            Console.WriteLine(addrList(i).ToString)
          Next
    
        Catch ex As SocketException
          Console.WriteLine(ex.StackTrace.ToString)
        End Try
    End Sub
End Class
68.178.206.138

Get Aliases from IPHostEntry

Imports System.Net
Imports System.Net.Sockets

Public Class Tester
    Public Shared Sub Main
        Dim localHostName As String
        Dim localHostEntry As IPHostEntry
        Dim aliasList As String()
        Dim addrList As IPAddress()
    
        Dim i As Integer
        Dim strTemp As String
    
        Try
          localHostName = Dns.GetHostName
    
          localHostEntry = Dns.GetHostByName(localHostName)
    
          Console.WriteLine(localHostEntry.HostName)
    
          aliasList = localHostEntry.Aliases
    
          For i = 0 To aliasList.Length - 1
            Console.WriteLine(aliasList(i).ToString)
          Next
          
          addrList = localHostEntry.AddressList
    
          For i = 0 To addrList.Length - 1
            Console.WriteLine(addrList(i).ToString)
          Next
        Catch ex As SocketException
          Console.WriteLine(ex.StackTrace.ToString)
        End Try
    End Sub
End Class
vbex
192.168.1.101

Get Host By Address

Imports System.Net
Imports System.Net.Sockets

Public Class Tester
    Public Shared Sub Main
        Dim ipAddr As IPAddress
        Dim remoteHostEntry As IPHostEntry
    
        Try
          ipAddr = IPAddress.Parse("68.178.206.138")
    
          remoteHostEntry = Dns.GetHostByAddress(ipAddr)
    
          Console.WriteLine(remoteHostEntry.HostName)
    
        Catch ex As SocketException
          Console.WriteLine(ex.StackTrace.ToString)
        End Try
    End Sub
End Class
ip-68-178-206-138.ip.secureserver.net

Get Host By Name

Imports System.Net
Imports System.Net.Sockets

Public Class Tester
    Public Shared Sub Main
        Dim localHostEntry As IPHostEntry
        Dim aliasList As String()
        Dim addrList As IPAddress()
    
        Dim i As Integer
        Dim strTemp As String
    
        Try
    
          localHostEntry = Dns.GetHostByName("www.vbex.ru")
    
          Console.WriteLine(localHostEntry.HostName)
    
          aliasList = localHostEntry.Aliases
    
          For i = 0 To aliasList.Length - 1
            Console.WriteLine(aliasList(i).ToString)
          Next
          
          addrList = localHostEntry.AddressList
    
          For i = 0 To addrList.Length - 1
            Console.WriteLine(addrList(i).ToString)
          Next
        Catch ex As SocketException
          Console.WriteLine(ex.StackTrace.ToString)
        End Try
    End Sub
End Class
vbex.ru
www.vbex.ru
68.178.206.138