IPAddress.Parse 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
| Name | Description |
|---|---|
| Parse(ReadOnlySpan<Char>) |
문자 범위로 표시되는 IP 주소를 인스턴스로 IPAddress 변환합니다. |
| Parse(String) |
IP 주소 문자열을 인스턴스로 IPAddress 변환합니다. |
| Parse(ReadOnlySpan<Byte>) |
UTF-8 문자의 범위를 값으로 구문 분석합니다. |
Parse(ReadOnlySpan<Char>)
- Source:
- IPAddress.cs
- Source:
- IPAddress.cs
- Source:
- IPAddress.cs
- Source:
- IPAddress.cs
- Source:
- 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)
- Source:
- IPAddress.cs
- Source:
- IPAddress.cs
- Source:
- IPAddress.cs
- Source:
- IPAddress.cs
- Source:
- 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에 대한 점 쿼드 표기법으로 표현된 IP 주소와 IPv6에 대한 콜론-16진수 표기법으로 인스턴스를 만듭니다 IPAddress .
IP 주소가 생성되는 방법을 결정하는 부분의 수(각 부분은 마침표로 구분됨) ipString 입니다. 한 부분 주소는 네트워크 주소에 직접 저장됩니다. 클래스 A 주소를 지정하는 데 편리한 두 부분 주소는 첫 번째 바이트에 선행 부분을 배치하고 후행 부분은 네트워크 주소의 오른쪽 3바이트 안에 배치합니다. 클래스 B 주소를 지정하는 데 편리한 3부 주소는 첫 번째 파트를 첫 번째 바이트, 두 번째 바이트의 두 번째 부분 및 네트워크 주소의 가장 오른쪽에 있는 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>)
- Source:
- IPAddress.cs
- Source:
- 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.