IPAddress.Parse メソッドとは? わかりやすく解説

IPAddress.Parse メソッド

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

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

ipStringnull 参照 (Visual Basic では Nothing) です。

FormatException

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

解説解説
使用例使用例

次のコードは、ピリオド区切り10 進表記 (IPv4場合) またはコロン区切り16 進表記 (IPv6 の場合) の IP アドレス格納する文字列を、IPAddress クラスインスタンス変換します次にオーバーロードされた ToString メソッド使用して標準表記アドレス表示します

Imports System
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 'Main
    
   
   ' 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 'parse 
End Class 'ParseAddress
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);
    }

   }
}
#using <System.dll>

using namespace System;
using namespace System::Net;

// 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.
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: \"{0}\"
 produces this address (shown in its standard
 notation): {1}", ipAddress, address );
   }
   catch ( ArgumentNullException^ e ) 
   {
      Console::WriteLine( "ArgumentNullException caught!!!" );
      Console::WriteLine( "Source : {0}", e->Source );
      Console::WriteLine( "Message : {0}", e->Message );
   }
   catch ( FormatException^ e ) 
   {
      Console::WriteLine( "FormatException caught!!!" );
      Console::WriteLine( "Source : {0}", e->Source );
      Console::WriteLine( "Message : {0}", e->Message );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception caught!!!" );
      Console::WriteLine( "Source : {0}", e->Source );
      Console::WriteLine( "Message : {0}", e->Message );
   }

}

int main()
{
   array<String^>^args = Environment::GetCommandLineArgs();
   String^ IPaddress;
   if ( args->Length == 1 )
   {
      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 0;
   }
   else
      IPaddress = args[ 1 ];

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

import System.*;
import System.Net.*;

class ParseAddress
{
    public static void main(String[]
 args)
    {
        String iPaddress;

        if (args.length == 0) {
            Console.WriteLine("Please enter an IP address.");
            Console.WriteLine("Usage:   >jsl_parse any IPv4 or IPv6 address.");
            Console.WriteLine("Example: >jsl_parse 127.0.0.1");
            Console.WriteLine("Example: >jsl_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);
    } //main
       
    // 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.get_Source()));
            Console.WriteLine(("Message : " + e.get_Message()));
        }
        catch(FormatException e) {
            Console.WriteLine("FormatException caught!!!");
            Console.WriteLine(("Source : " + e.get_Source()));
            Console.WriteLine(("Message : " + e.get_Message()));
        }
         catch(System.Exception e) {
              Console.WriteLine("Exception caught!!!");
            Console.WriteLine(("Source : " + e.get_Source()));
            Console.WriteLine(("Message : " + e.get_Message()));
        }
     } //Parse
} //ParseAddress
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「IPAddress.Parse メソッド」の関連用語

IPAddress.Parse メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



IPAddress.Parse メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS