本文整理汇总了VB.NET中System.Net.IPAddress.Parse方法的典型用法代码示例。如果您正苦于以下问题:VB.NET IPAddress.Parse方法的具体用法?VB.NET IPAddress.Parse怎么用?VB.NET IPAddress.Parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.IPAddress
的用法示例。
在下文中一共展示了IPAddress.Parse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: ParseAddress
' 导入命名空间
Imports System.Net
Class ParseAddress
'Entry point which delegates to C-style main Private Function
Public Overloads Shared Sub Main()
Main(System.Environment.GetCommandLineArgs())
End Sub
Overloads Private Shared Sub Main(args() As String)
Dim IPaddress As String
If args.Length = 1 Then
Console.WriteLine("Please enter an IP address.")
Console.WriteLine("Usage: >cs_parse any IPv4 or IPv6 address.")
Console.WriteLine("Example: >cs_parse 127.0.0.1")
Console.WriteLine("Example: >cs_parse 0:0:0:0:0:0:0:1")
Return
Else
IPaddress = args(1)
End If
' Get the list of the IPv6 addresses associated with the requested host.
Parse(IPaddress)
End Sub
' This method calls the IPAddress.Parse method to check the ipAddress
' input string. If the ipAddress argument represents a syntatical correct IPv4 or
' IPv6 address, the method displays the Parse output into quad-notation or
' colon-hexadecimal notation, respectively. Otherwise, it displays an
' error message.
Private Shared Sub Parse(ipAddr As String)
Try
' Create an instance of IPAddress for the specified address string (in
' dotted-quad, or colon-hexadecimal notation).
Dim address As IPAddress = IPAddress.Parse(ipAddr)
' Display the address in standard notation.
Console.WriteLine(("Parsing your input string: " + """" + ipAddr + """" + " produces this address (shown in its standard notation): " + address.ToString()))
Catch e As ArgumentNullException
Console.WriteLine("ArgumentNullException 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 Exception
Console.WriteLine("Exception caught!!!")
Console.WriteLine(("Source : " + e.Source))
Console.WriteLine(("Message : " + e.Message))
End Try
End Sub
End Class
示例2: Tester
' 导入命名空间
Imports System.Net
Public Class Tester
Public Shared Sub Main
Dim ipAddr1 As IPAddress = IPAddress.Parse("192.168.1.100")
Dim ipAddr2 As IPAddress = IPAddress.Parse("192.168.1.100")
If ipAddr1.Equals(ipAddr2) Then
Console.WriteLine("equal")
Else
Console.WriteLine("different")
End If
End Sub
End Class