当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET IPAddress.Parse方法代码示例

本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:System.Net,代码行数:61,代码来源:IPAddress.Parse

示例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
开发者ID:VB程序员,项目名称:System.Net,代码行数:15,代码来源:IPAddress.Parse


注:本文中的System.Net.IPAddress.Parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。