IPAddress.Parse メソッド
アセンブリ: System (system.dll 内)

Dim ipString As String Dim returnValue As IPAddress returnValue = IPAddress.Parse(ipString)
戻り値
IPAddress のインスタンス。


静的 Parse メソッドは、ピリオド区切りの 10 進表記 (IPv4 の場合) またはコロン区切りの 16 進表記 (IPv6 の場合) で表された IP アドレスから IPAddress のインスタンスを作成します。
IP アドレスの構築方法は、ipString 内のピリオドで区切られた部分の数によって決まります。1 つの部分から成るアドレスは、ネットワーク アドレスに直接格納されます。クラス A のアドレスを指定する場合に便利な 2 つの部分から成るアドレスでは、先頭の部分がネットワーク アドレスの第 1 バイト、末尾の部分が右端の 3 バイトに配置されます。クラス B のアドレスを指定する場合に便利な 3 つの部分から成るアドレスでは、先頭の部分がネットワーク アドレスの第 1 バイト、2 番目の部分が第 2 バイト、最後の部分が右端の 2 バイトに配置されます。次に例を示します。
部分の数と ipString の例 | |
---|---|
1 -- "65536" | 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 |

次のコードは、ピリオド区切りの 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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- IPAddress.Parse メソッドのページへのリンク