Jazyk

IPAddress.Parse Metoda

Definice

Přetížení

Název Description
Parse(ReadOnlySpan<Char>)

Převede IP adresu reprezentovanou jako rozsah znaků na IPAddress instanci.

Parse(String)

Převede řetězec IP adresy na IPAddress instanci.

Parse(ReadOnlySpan<Byte>)

Parsuje rozsah znaků UTF-8 do hodnoty.

Parse(ReadOnlySpan<Char>)

Zdroj:
IPAddress.cs
Zdroj:
IPAddress.cs
Zdroj:
IPAddress.cs
Zdroj:
IPAddress.cs
Zdroj:
IPAddress.cs

Převede IP adresu reprezentovanou jako rozsah znaků na IPAddress instanci.

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

Parametry

ipStringipSpan
ReadOnlySpan<Char>

Rozsah znaků, který obsahuje IP adresu v tečkované čtyřúhelníku pro protokol IPv4 a v šestnáctkovém zápisu pro protokol IPv6.

Návraty

Převedená IP adresa.

Výjimky

ipString není platná IP adresa.

Platí pro

Parse(String)

Zdroj:
IPAddress.cs
Zdroj:
IPAddress.cs
Zdroj:
IPAddress.cs
Zdroj:
IPAddress.cs
Zdroj:
IPAddress.cs

Převede řetězec IP adresy na IPAddress instanci.

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

Parametry

ipString
String

Řetězec, který obsahuje IP adresu v zápisu IPv4 s tečkovaným čtyřúhelníkem a dvojtečkovým šestnáctkovým zápisem pro protokol IPv6.

Návraty

Instance IPAddress .

Výjimky

ipString je null.

ipString není platná IP adresa.

Příklady

Následující kód převede řetězec, který obsahuje IP adresu, v tečkované čtyřúhelníku pro IPv4 nebo v dvojtečce šestnáctkové notace pro IPv6, do instance IPAddress třídy. Pak použije přetíženou ToString metodu k zobrazení adresy ve standardním zápisu.


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

Poznámky

Statická Parse metoda vytvoří IPAddress instanci z IP adresy vyjádřené v tečkované čtyřúhelníku pro protokol IPv4 a v šestnáctkové notaci pro protokol IPv6.

Počet částí (každá část je oddělená tečkou) určuje ipString způsob vytváření IP adresy. Jedna část adresy je uložena přímo v síťové adrese. Adresa dvě části, která je vhodná pro zadání adresy A třídy, umístí úvodní část do prvního bajtu a koncové části do pravého tří bajtů síťové adresy. Třídílná adresa, která je vhodná pro zadání adresy třídy B, vloží první část do prvního bajtu, druhou část druhého bajtu a poslední část na pravé straně dvou bajtů síťové adresy. Příklad:

Počet částí a příklad ipString Adresa IPv4 pro IPAddress
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

Platí pro

Parse(ReadOnlySpan<Byte>)

Zdroj:
IPAddress.cs
Zdroj:
IPAddress.cs

Parsuje rozsah znaků UTF-8 do hodnoty.

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

Parametry

utf8Text
ReadOnlySpan<Byte>

Rozsah znaků UTF-8 pro analýzu.

Návraty

Výsledek analýzy utf8Text.

Platí pro