Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Konvertiert eine IP-Adresszeichenfolge in eine IPAddress-Instanz.
Namespace: System.Net
Assembly: System (in system.dll)
Syntax
'Declaration
Public Shared Function Parse ( _
ipString As String _
) As IPAddress
'Usage
Dim ipString As String
Dim returnValue As IPAddress
returnValue = IPAddress.Parse(ipString)
public static IPAddress Parse (
string ipString
)
public:
static IPAddress^ Parse (
String^ ipString
)
public static IPAddress Parse (
String ipString
)
public static function Parse (
ipString : String
) : IPAddress
Parameter
- ipString
Eine Zeichenfolge, die eine IP-Adresse im Punktformat (Dotted Quad-Notation) für IPv4 und im durch Doppelpunkt getrennten Hexadezimalformat für IPv6 enthält.
Rückgabewert
Eine IPAddress-Instanz.
Ausnahmen
| Ausnahmetyp | Bedingung |
|---|---|
ipString ist NULL (Nothing in Visual Basic). |
|
ipString ist keine gültige IP-Adresse. |
Hinweise
Diese statische Parse-Methode erstellt eine IPAddress-Instanz aus einer IP-Adresse für IPv4 im Punktformat oder für IPv6 im durch Doppelpunkt getrennten Hexadezimalformat.
Durch die Anzahl der Teile (die einzelnen Teile sind durch einen Punkt getrennt) in ipString wird bestimmt, wie die IP-Adresse erstellt wird. Eine Adresse mit nur einem Teil wird direkt in der Netzwerkadresse gespeichert. Bei einer Adresse mit zwei Teilen (geeignet zum Angeben einer Adresse der Klasse A) wird der führende Teil im ersten Byte und der nachstehende Teil in den letzten drei Bytes der Netzwerkadresse abgelegt. Bei einer Adresse mit drei Teilen (geeignet zum Angeben einer Adresse der Klasse B) wird der erste Teil im ersten Byte, der zweite Teil im zweiten Byte und der letzte Teil in den zwei letzten Bytes in der Netzwerkadresse abgelegt. Beispiel:
Anzahl der Teile und Beispiel-ipString |
IPv4-Adresse für IPAddress |
|---|---|
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 |
Beispiel
Im folgenden Code wird eine Zeichenfolge mit einer IP-Adresse im Punktformat für IPv4 bzw. im durch Doppelpunkt getrennten Hexadezimalformat für IPv6 in eine Instanz der IPAddress-Klasse konvertiert. Anschließend wird mithilfe der überladenen ToString-Methode die Adresse im Standardformat angezeigt.
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
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0