本文整理汇总了VB.NET中System.Net.Dns.GetHostName方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Dns.GetHostName方法的具体用法?VB.NET Dns.GetHostName怎么用?VB.NET Dns.GetHostName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Dns.GetHostName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: DisplayLocalHostName
Public Sub DisplayLocalHostName()
Try
' Get the local computer host name.
Dim hostName As [String] = Dns.GetHostName()
Console.WriteLine(("Computer name :" + hostName))
Catch e As SocketException
Console.WriteLine("SocketException 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
示例2: Dns.GetHostName()
' 导入命名空间
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