IPAddressとは? わかりやすく解説

IPAddress クラス

インターネット プロトコル (IP: Internet Protocol) アドレス提供します

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

<SerializableAttribute> _
Public Class IPAddress
[SerializableAttribute] 
public class IPAddress
[SerializableAttribute] 
public ref class IPAddress
/** @attribute SerializableAttribute() */ 
public class IPAddress
SerializableAttribute 
public class IPAddress
解説解説
使用例使用例

サーバー問い合わせてファミリ アドレスおよびそのサーバーサポートする IP アドレス取得する方法次の例に示します

' This program shows how to use the IPAddress class to obtain a server
 
' IP addressess and related information.
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text.RegularExpressions
Imports Microsoft.VisualBasic


Namespace Mssc.Services.ConnectionManagement
  Module M_TestIPAddress

    Class TestIPAddress

      'The IPAddresses method obtains the selected server IP address
 information.
      'It then displays the type of address family supported by the
 server and 
      'its IP address in standard and byte format.
      Private Shared Sub
 IPAddresses(ByVal server As String)
        Try
          Dim ASCII As New
 System.Text.ASCIIEncoding()

          ' Get server related information.
          Dim heserver As IPHostEntry = Dns.Resolve(server)

          ' Loop on the AddressList
          Dim curAdd As IPAddress
          For Each curAdd In
 heserver.AddressList

            ' Display the type of address family supported by the server.
 If the
            ' server is IPv6-enabled this value is: InternNetworkV6.
 If the server
            ' is also IPv4-enabled there will be an additional value
 of InterNetwork.
            Console.WriteLine(("AddressFamily: " +
 curAdd.AddressFamily.ToString()))

            ' Display the ScopeId property in case of IPV6 addresses.
            If curAdd.AddressFamily.ToString() = ProtocolFamily.InterNetworkV6.ToString()
 Then
              Console.WriteLine(("Scope Id: " + curAdd.ScopeId.ToString()))
            End If

            ' Display the server IP address in the standard format.
 In 
            ' IPv4 the format will be dotted-quad notation, in IPv6
 it will be
            ' in in colon-hexadecimal notation.
            Console.WriteLine(("Address: " + curAdd.ToString()))

            ' Display the server IP address in byte format.
            Console.Write("AddressBytes: ")



            Dim bytes As [Byte]() = curAdd.GetAddressBytes()
            Dim i As Integer
            For i = 0 To bytes.Length - 1
              Console.Write(bytes(i))
            Next i
            Console.WriteLine(ControlChars.Cr + ControlChars.Lf)
          Next curAdd 

        Catch e As Exception
          Console.WriteLine(("[DoResolve] Exception: "
 + e.ToString()))
        End Try
      End Sub 'IPAddresses


      ' This IPAddressAdditionalInfo displays additional server address
 information.
      Private Shared Sub
 IPAddressAdditionalInfo()
        Try
          ' Display the flags that show if the server supports IPv4
 or IPv6
          ' address schemas.
          Console.WriteLine((ControlChars.Cr + ControlChars.Lf + "SupportsIPv4:
 " + Socket.SupportsIPv4.ToString()))
          Console.WriteLine(("SupportsIPv6: " + Socket.SupportsIPv6.ToString()))

          If Socket.SupportsIPv6 Then
            ' Display the server Any address. This IP address indicates
 that the server 
            ' should listen for client activity on all network interfaces.
 
            Console.WriteLine((ControlChars.Cr + ControlChars.Lf + "IPv6Any:
 " + IPAddress.IPv6Any.ToString()))

            ' Display the server loopback address. 
            Console.WriteLine(("IPv6Loopback: " +
 IPAddress.IPv6Loopback.ToString()))

            ' Used during autoconfiguration first phase.
            Console.WriteLine(("IPv6None: " + IPAddress.IPv6None.ToString()))

            Console.WriteLine(("IsLoopback(IPv6Loopback): "
 + IPAddress.IsLoopback(IPAddress.IPv6Loopback).ToString()))
          End If
          Console.WriteLine(("IsLoopback(Loopback): "
 + IPAddress.IsLoopback(IPAddress.Loopback).ToString()))
        Catch e As Exception
          Console.WriteLine(("[IPAddresses] Exception: "
 + e.ToString()))
        End Try
      End Sub 'IPAddressAdditionalInfo

      Public Shared Sub
 Main(ByVal args() As String)
        Dim server As String
 = Nothing

        ' Define a regular expression to parse user's input.
        ' This is a security check. It allows only
        ' alphanumeric input string between 2 to 40 character long.
        'Define a regular expression to parse user's input.
        'This is a security check. It allows only
        'alphanumeric input string between 2 to 40 character long.
        Dim rex As New Regex("^[a-zA-Z]\w{1
,39}$")

        If args.Length < 1 Then
          ' If no server name is passed as an argument to this program,
 use the current 
          ' server name as default.
          server = Dns.GetHostName()
          Console.WriteLine(("Using current host: "
 + server))
        Else
          server = args(0)
          If Not rex.Match(server).Success
 Then
            Console.WriteLine("Input string format not allowed.")
            Return
          End If
        End If

        ' Get the list of the addresses associated with the requested
 server.
        IPAddresses(server)

        ' Get additonal address information.
        IPAddressAdditionalInfo()
      End Sub 'Main
    End Class 'TestIPAddress
  End Module
End Namespace
// This program shows how to use the IPAddress class to obtain a server
 
// IP addressess and related information.

using System;
using System.Net;
using System.Net.Sockets;
using System.Text.RegularExpressions;

namespace Mssc.Services.ConnectionManagement
{

  class TestIPAddress 
  {

    /**
      * The IPAddresses method obtains the selected server IP address information.
      * It then displays the type of address family supported by the server and its
 
      * IP address in standard and byte format.
      **/
    private static void
 IPAddresses(string server) 
    {
      try 
      {
        System.Text.ASCIIEncoding ASCII = new System.Text.ASCIIEncoding();
  
        // Get server related information.
        IPHostEntry heserver = Dns.Resolve(server);

        // Loop on the AddressList
        foreach (IPAddress curAdd in heserver.AddressList)
 
        {


          // Display the type of address family supported by the server.
 If the
          // server is IPv6-enabled this value is: InternNetworkV6.
 If the server
          // is also IPv4-enabled there will be an additional value
 of InterNetwork.
          Console.WriteLine("AddressFamily: " + curAdd.AddressFamily.ToString());
          
          // Display the ScopeId property in case of IPV6 addresses.
          if(curAdd.AddressFamily.ToString() == ProtocolFamily.InterNetworkV6.ToString())
            Console.WriteLine("Scope Id: " + curAdd.ScopeId.ToString());


          // Display the server IP address in the standard format. In
 
          // IPv4 the format will be dotted-quad notation, in IPv6 it
 will be
          // in in colon-hexadecimal notation.
          Console.WriteLine("Address: " + curAdd.ToString());
        
          // Display the server IP address in byte format.
          Console.Write("AddressBytes: ");



          Byte[] bytes = curAdd.GetAddressBytes();
          for (int i = 0; i < bytes.Length;
 i++) 
          {
            Console.Write(bytes[i]);
          }                          

          Console.WriteLine("\r\n");

        }

      }
      catch (Exception e) 
      {
        Console.WriteLine("[DoResolve] Exception: " + e.ToString());
      }
    }

    // This IPAddressAdditionalInfo displays additional server address
 information.
    private static void
 IPAddressAdditionalInfo() 
    {
      try 
      {
        // Display the flags that show if the server supports IPv4 or
 IPv6
        // address schemas.
        Console.WriteLine("\r\nSupportsIPv4: " + Socket.SupportsIPv4);
        Console.WriteLine("SupportsIPv6: " + Socket.SupportsIPv6);

        if (Socket.SupportsIPv6)
        {
          // Display the server Any address. This IP address indicates
 that the server 
          // should listen for client activity on all network interfaces.
 
          Console.WriteLine("\r\nIPv6Any: " + IPAddress.IPv6Any.ToString());

          // Display the server loopback address. 
          Console.WriteLine("IPv6Loopback: " + IPAddress.IPv6Loopback.ToString());
      
          // Used during autoconfiguration first phase.
          Console.WriteLine("IPv6None: " + IPAddress.IPv6None.ToString());
      
          Console.WriteLine("IsLoopback(IPv6Loopback): " + IPAddress.IsLoopback(IPAddress.IPv6Loopback));
        }
        Console.WriteLine("IsLoopback(Loopback): " + IPAddress.IsLoopback(IPAddress.Loopback));
      }
      catch (Exception e) 
      {
        Console.WriteLine("[IPAddresses] Exception: " + e.ToString());
      }
    }


    public static void Main(string[]
 args) 
    {
      string server = null;
    
      // Define a regular expression to parse user's input.
      // This is a security check. It allows only
      // alphanumeric input string between 2 to 40 character long.
      Regex rex = new Regex(@"^[a-zA-Z]\w{1,39}$");

      if (args.Length < 1)
      {
        // If no server name is passed as an argument to this program,
 use the current 
        // server name as default.
        server = Dns.GetHostName();
        Console.WriteLine("Using current host: " + server);
      }
      else
      {
        server = args[0];
        if (!(rex.Match(server)).Success)
        {
          Console.WriteLine("Input string format not allowed.");
          return;
        }
      }

      // Get the list of the addresses associated with the requested
 server.
      IPAddresses(server);
    
      // Get additonal address information.
      IPAddressAdditionalInfo();
    }

  }
}
// This program shows how to use the IPAddress class to obtain a server
 
// IP addressess and related information.
import System.*;
import System.Net.*;
import System.Net.Sockets.*;
import System.Text.RegularExpressions.*;

class TestIPAddress
{
    /**
       The IPAddresses method obtains the selected server IP address 
       information.It then displays the type of address family supported by 
       the server and its IP address in standard and byte format.
     */
    private static void
 IPAddresses(String server)
    {
        try {
            System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();

            // Get server related information.
            IPHostEntry heserver = Dns.Resolve(server);
            // Loop on the AddressList
            for (int iCtr = 0; iCtr < heserver.get_AddressList().length;
                iCtr++) {            
                IPAddress curAdd = heserver.get_AddressList()[iCtr];

                // Display the type of address family supported by the
 server. 
                // If the server is IPv6-enabled this value is:InternNetworkV6.
                // If the server is also IPv4-enabled there will be
 an 
                // additional value of InterNetwork.
                Console.WriteLine(("AddressFamily: " 
                    + curAdd.get_AddressFamily().ToString()));

                // Display the ScopeId property in case of IPV6 addresses.
                if (curAdd.get_AddressFamily().ToString().equals(
                        ProtocolFamily.InterNetworkV6.ToString())) {
                    Console.WriteLine(("Scope Id: " 
                        +(new Long(curAdd.get_ScopeId())).ToString()));
                }

                // Display the server IP address in the standard format. In
 
                // IPv4 the format will be dotted-quad notation, in
 IPv6 
                // it will be in in colon-hexadecimal notation.
                Console.WriteLine(("Address: " + curAdd.ToString()));
                // Display the server IP address in byte format.
                Console.Write("AddressBytes: ");

                ubyte bytes[] = curAdd.GetAddressBytes();
                for (int i = 0; i < bytes.length;
 i++) {
                    Console.Write(bytes[i]);
                }
                Console.WriteLine("\r\n");
            }
        }
        catch (System.Exception e) {
            Console.WriteLine(("[DoResolve] Exception: " + e.ToString()));
        }    
    } //IPAddresses

    // This IPAddressAdditionalInfo displays additional server address
 
    // information.
    private static void
 IPAddressAdditionalInfo()
    {
        try {
            // Display the flags that show if the server supports IPv4 or
 IPv6
            // address schemas.
            Console.WriteLine("\r\nSupportsIPv4: " 
                + System.Convert.ToString(Socket.get_SupportsIPv4()));
            Console.WriteLine("SupportsIPv6: " 
                + System.Convert.ToString(Socket.get_SupportsIPv6()));
            if (Socket.get_SupportsIPv6()) {
                // Display the server Any address. This IP address indicates
 
                // that the server should listen for client activity
 on all 
                // network interfaces. 
                Console.WriteLine(("\r\nIPv6Any: " 
                    + (IPAddress.IPv6Any).ToString()));

                // Display the server loopback address. 
                Console.WriteLine(("IPv6Loopback: "
                    + (IPAddress.IPv6Loopback).ToString()));

                // Used during autoconfiguration first phase.
                Console.WriteLine(("IPv6None: " 
                    + (IPAddress.IPv6None).ToString()));
                Console.WriteLine(("IsLoopback(IPv6Loopback): " 
                    + IPAddress.IsLoopback(IPAddress.IPv6Loopback)));
            }
            Console.WriteLine(("IsLoopback(Loopback): " 
                + System.Convert.ToString(IPAddress.
                IsLoopback(IPAddress.Loopback))));
        }
        catch (System.Exception e) {
            Console.WriteLine(("[IPAddresses] Exception: " + e.ToString()));
        } 
    } //IPAddressAdditionalInfo

    public static void main(String[]
 args)
    {
        String server = null;
        // Define a regular expression to parse user's input.
        // This is a security check. It allows only
        // alphanumeric input string between 2 to 40 character long.
        Regex rex = new Regex("^[a-zA-Z]\\w{1,39}$");
        if (args.length < 1) {
            // If no server name is passed as an argument to this program,
 
            // use the current server name as default.
            server = Dns.GetHostName();
            Console.WriteLine(("Using current host: " + server));
        } 
        else {
            server = args[0];
            if (!(rex.Match(server).get_Success())) {
                Console.WriteLine("Input string format not
 allowed.");
                return;
            } 
        } 
        // Get the list of the addresses associated with the requested
 server.
        IPAddresses(server);

        // Get additonal address information.
        IPAddressAdditionalInfo();
    } //main
} //TestIPAddress
継承階層継承階層
System.Object
  System.Net.IPAddress
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

IPAddress コンストラクタ (Int64)

Int64 として指定されアドレス使用して、IPAddress クラス新しインスタンス初期化します。

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

Public Sub New ( _
    newAddress As Long _
)
Dim newAddress As Long

Dim instance As New IPAddress(newAddress)
public IPAddress (
    long newAddress
)
public:
IPAddress (
    long long newAddress
)
public IPAddress (
    long newAddress
)
public function IPAddress (
    newAddress : long
)

パラメータ

newAddress

IP アドレスlong 値。たとえば、ビッグ エンディアン形式の値 0x2414188f は、IP アドレス "143.24.20.36" になります

解説解説

IPAddressインスタンスが、Address プロパティnewAddress設定された状態で作成されます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

IPAddress コンストラクタ (Byte[], Int64)

指定したアドレススコープ使用して、IPAddress クラス新しインスタンス初期化します。

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

Public Sub New ( _
    address As Byte(), _
    scopeid As Long _
)
Dim address As Byte()
Dim scopeid As Long

Dim instance As New IPAddress(address,
 scopeid)
public IPAddress (
    byte[] address,
    long scopeid
)
public:
IPAddress (
    array<unsigned char>^ address, 
    long long scopeid
)
public IPAddress (
    byte[] address, 
    long scopeid
)
public function IPAddress (
    address : byte[], 
    scopeid : long
)

パラメータ

address

IP アドレスバイト配列値。

scopeid

スコープ識別子long 値。

例外例外
例外種類条件

ArgumentNullException

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

ArgumentOutOfRangeException

scopeid < 0 または

scopeid > 0x00000000FFFFFFFF

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

IPAddress コンストラクタ


IPAddress コンストラクタ (Byte[])

Byte 配列として指定されアドレス使用して、IPAddress クラス新しインスタンス初期化します。

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

例外例外
例外種類条件

ArgumentNullException

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

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

IPAddress フィールド


IPAddress プロパティ


IPAddress メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

IPAddress クラス
System.Net 名前空間

IPAddress メンバ

インターネット プロトコル (IP: Internet Protocol) アドレス提供します

IPAddress データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック フィールドパブリック フィールド
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

IPAddress クラス
System.Net 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からIPAddressを検索した結果を表示しています。
Weblioに収録されているすべての辞書からIPAddressを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からIPAddress を検索

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

辞書ショートカット

すべての辞書の索引

「IPAddress」の関連用語

IPAddressのお隣キーワード
検索ランキング

   

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



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

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

©2025 GRAS Group, Inc.RSS