Language

IPAddress.Parse メソッド

定義

オーバーロード

名前 説明
Parse(ReadOnlySpan<Char>)

文字スパンとして表される IP アドレスを IPAddress インスタンスに変換します。

Parse(String)

IP アドレス文字列を IPAddress インスタンスに変換します。

Parse(ReadOnlySpan<Byte>)

UTF-8 文字のスパンを値に解析します。

Parse(ReadOnlySpan<Char>)

ソース:
IPAddress.cs
ソース:
IPAddress.cs
ソース:
IPAddress.cs
ソース:
IPAddress.cs
ソース:
IPAddress.cs

文字スパンとして表される IP アドレスを IPAddress インスタンスに変換します。

public:
 static System::Net::IPAddress ^ Parse(ReadOnlySpan<char> ipSpan);
public:
 static System::Net::IPAddress ^ Parse(ReadOnlySpan<char> ipString);
public static System.Net.IPAddress Parse(ReadOnlySpan<char> ipSpan);
public static System.Net.IPAddress Parse(ReadOnlySpan<char> ipString);
static member Parse : ReadOnlySpan<char> -> System.Net.IPAddress
static member Parse : ReadOnlySpan<char> -> System.Net.IPAddress
Public Shared Function Parse (ipSpan As ReadOnlySpan(Of Char)) As IPAddress
Public Shared Function Parse (ipString As ReadOnlySpan(Of Char)) As IPAddress

パラメーター

ipStringipSpan
ReadOnlySpan<Char>

IPv4 の場合はドットクワッド表記、IPv6 の場合はコロン 16 進数表記の IP アドレスを含む文字スパン。

返品

変換された IP アドレス。

例外

ipString が有効な IP アドレスではありません。

適用対象

Parse(String)

ソース:
IPAddress.cs
ソース:
IPAddress.cs
ソース:
IPAddress.cs
ソース:
IPAddress.cs
ソース:
IPAddress.cs

IP アドレス文字列を IPAddress インスタンスに変換します。

public:
 static System::Net::IPAddress ^ Parse(System::String ^ ipString);
public static System.Net.IPAddress Parse(string ipString);
static member Parse : string -> System.Net.IPAddress
Public Shared Function Parse (ipString As String) As IPAddress

パラメーター

ipString
String

IPv4 の場合はドット付きクワッド表記、IPv6 の場合はコロン 16 進数表記の IP アドレスを含む文字列。

返品

IPAddress インスタンス。

例外

ipString は nullです。

ipString が有効な IP アドレスではありません。

例

次のコードは、IP アドレスを含む文字列を、IPv4 の場合はドット四角表記で、IPv6 の場合はコロン 16 進数表記で、 IPAddress クラスのインスタンスに変換します。 次に、オーバーロードされた ToString メソッドを使用して、標準表記でアドレスを表示します。


using System;
using System.Net;

class ParseAddress
{

  private static void Main(string[] args)
  {
    string IPaddress;

    if (args.Length == 0)
    {
      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[0];
        }

        // Get the list of the IPv6 addresses associated with the requested host.
        Parse(IPaddress);
  }

  // This method calls the IPAddress.Parse method to check the ipAddress
  // input string. If the ipAddress argument represents a syntatically 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 static void Parse(string ipAddress)
  {
    try
    {
      // Create an instance of IPAddress for the specified address string (in
      // dotted-quad, or colon-hexadecimal notation).
      IPAddress address = IPAddress.Parse(ipAddress);

      // Display the address in standard notation.
      Console.WriteLine("Parsing your input string: " + "\"" + ipAddress + "\"" + " produces this address (shown in its standard notation): "+ address.ToString());
    }

    catch(ArgumentNullException e)
    {
      Console.WriteLine("ArgumentNullException caught!!!");
      Console.WriteLine("Source : " + e.Source);
      Console.WriteLine("Message : " + e.Message);
    }

    catch(FormatException e)
    {
      Console.WriteLine("FormatException caught!!!");
      Console.WriteLine("Source : " + e.Source);
      Console.WriteLine("Message : " + e.Message);
    }

    catch(Exception e)
    {
      Console.WriteLine("Exception caught!!!");
      Console.WriteLine("Source : " + e.Source);
      Console.WriteLine("Message : " + e.Message);
    }
   }
}
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

注釈

静的 Parse メソッドは、IPv4 のドットクワッド表記と IPv6 のコロン 16 進数表記で表された IP アドレスから、 IPAddress インスタンスを作成します。

ipString内のパーツの数 (各部分はピリオドで区切られています) によって、IP アドレスの構成方法が決まります。 1 つの部分のアドレスは、ネットワーク アドレスに直接格納されます。 クラス A アドレスを指定する場合に便利な 2 つの部分のアドレスは、先頭部分を最初のバイトに、末尾の部分をネットワーク アドレスの右端の 3 バイトに置きます。 クラス B アドレスを指定する場合に便利な 3 つの部分のアドレスは、最初の部分を最初のバイトに、2 番目の部分を 2 番目のバイトに、最後の部分をネットワーク アドレスの右端の 2 バイトに配置します。 例えば次が挙げられます。

部品数と例 ipString IPAddress の IPv4 アドレス
1 -- "65535" 0.0.255.255
2 -- "20.2" 20.0.0.2
2 -- "20.65535" 20.0.255.255
3 -- "128.1.2" 128.1.0.2
4 -- "1.1.1.10" 1.1.1.10
4 -- "1.1.1.010" 1.1.1.8
1 -- "0x2F" 0.0.0.47

適用対象

Parse(ReadOnlySpan<Byte>)

ソース:
IPAddress.cs
ソース:
IPAddress.cs

UTF-8 文字のスパンを値に解析します。

public:
 static System::Net::IPAddress ^ Parse(ReadOnlySpan<System::Byte> utf8Text);
public static System.Net.IPAddress Parse(ReadOnlySpan<byte> utf8Text);
static member Parse : ReadOnlySpan<byte> -> System.Net.IPAddress
Public Shared Function Parse (utf8Text As ReadOnlySpan(Of Byte)) As IPAddress

パラメーター

utf8Text
ReadOnlySpan<Byte>

解析する UTF-8 文字のスパン。

返品

utf8Text解析の結果。

適用対象