PrefixOrigin 列舉

定義

指定如何找到 IP 位址網路首碼。

public enum class PrefixOrigin
public enum PrefixOrigin
type PrefixOrigin = 
Public Enum PrefixOrigin
繼承
PrefixOrigin

欄位

Dhcp 3

首碼是由動態主機設定通訊協定 (DHCP) 伺服器所提供。

Manual 1

首碼是以手動方式設定。

Other 0

首碼是使用未指定的來源找到的。

RouterAdvertisement 4

首碼是由路由器通告所提供。

WellKnown 2

首碼是已知的首碼。 已知的首碼是在標準 Request for Comments (RFC) 文件中所指定,並由 Internet Assigned Numbers Authority (IANA) 或位址登錄所指派。 這類首碼會保留供特殊目的使用。

範例

下列程式碼範例會顯示單播位址的前置詞和尾碼資訊。

void DisplayUnicastAddresses()
{
   Console::WriteLine( "Unicast Addresses" );
   array<NetworkInterface^>^adapters = NetworkInterface::GetAllNetworkInterfaces();
   System::Collections::IEnumerator^ myEnum17 = adapters->GetEnumerator();
   while ( myEnum17->MoveNext() )
   {
      NetworkInterface ^ adapter = safe_cast<NetworkInterface ^>(myEnum17->Current);
      IPInterfaceProperties ^ adapterProperties = adapter->GetIPProperties();
      UnicastIPAddressInformationCollection ^ uniCast = adapterProperties->UnicastAddresses;
      if ( uniCast->Count > 0 )
      {
         Console::WriteLine( adapter->Description );
         String^ lifeTimeFormat = "dddd, MMMM dd, yyyy  hh:mm:ss tt";
         System::Collections::IEnumerator^ myEnum18 = uniCast->GetEnumerator();
         while ( myEnum18->MoveNext() )
         {
            UnicastIPAddressInformation ^ uni = safe_cast<UnicastIPAddressInformation ^>(myEnum18->Current);
            DateTime when;
            Console::WriteLine( "  Unicast Address ......................... : {0}", 
               uni->Address );
            Console::WriteLine( "     Prefix Origin ........................ : {0}", 
               uni->PrefixOrigin );
            Console::WriteLine( "     Suffix Origin ........................ : {0}", 
               uni->SuffixOrigin );
            Console::WriteLine( "     Duplicate Address Detection .......... : {0}", 
               uni->DuplicateAddressDetectionState );
            
            // Format the lifetimes as Sunday, February 16, 2003 11:33:44 PM
            // if en-us is the current culture.
            // Calculate the date and time at the end of the lifetimes.    
            when = DateTime::UtcNow + TimeSpan::FromSeconds( (double)uni->AddressValidLifetime );
            when = when.ToLocalTime();
            Console::WriteLine( "     Valid Life Time ...................... : {0}", 
               when.ToString( lifeTimeFormat, System::Globalization::CultureInfo::CurrentCulture ) );
            when = DateTime::UtcNow + TimeSpan::FromSeconds( (double)uni->AddressPreferredLifetime );
            when = when.ToLocalTime();
            Console::WriteLine( "     Preferred life time .................. : {0}", 
               when.ToString( lifeTimeFormat, System::Globalization::CultureInfo::CurrentCulture ) );
            when = DateTime::UtcNow + TimeSpan::FromSeconds( (double)uni->DhcpLeaseLifetime );
            when = when.ToLocalTime();
            Console::WriteLine( "     DHCP Leased Life Time ................ : {0}", 
               when.ToString( lifeTimeFormat, System::Globalization::CultureInfo::CurrentCulture ) );
         }
         Console::WriteLine();
      }
   }
}
public static void DisplayUnicastAddresses()
{
    Console.WriteLine("Unicast Addresses");
    NetworkInterface[] adapters  = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface adapter in adapters)
    {
        IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
        UnicastIPAddressInformationCollection uniCast = adapterProperties.UnicastAddresses;
        if (uniCast.Count >0)
        {
            Console.WriteLine(adapter.Description);
            string lifeTimeFormat = "dddd, MMMM dd, yyyy  hh:mm:ss tt";
            foreach (UnicastIPAddressInformation uni in uniCast)
            {
                DateTime when;

                Console.WriteLine("  Unicast Address ......................... : {0}", uni.Address);
                Console.WriteLine("     Prefix Origin ........................ : {0}", uni.PrefixOrigin);
                Console.WriteLine("     Suffix Origin ........................ : {0}", uni.SuffixOrigin);
                Console.WriteLine("     Duplicate Address Detection .......... : {0}",
                    uni.DuplicateAddressDetectionState);

                // Format the lifetimes as Sunday, February 16, 2003 11:33:44 PM
                // if en-us is the current culture.

                // Calculate the date and time at the end of the lifetimes.
                when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressValidLifetime);
                when = when.ToLocalTime();
                Console.WriteLine("     Valid Life Time ...................... : {0}",
                    when.ToString(lifeTimeFormat,System.Globalization.CultureInfo.CurrentCulture)
                );
                when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressPreferredLifetime);
                when = when.ToLocalTime();
                Console.WriteLine("     Preferred life time .................. : {0}",
                    when.ToString(lifeTimeFormat,System.Globalization.CultureInfo.CurrentCulture)
                );

                when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.DhcpLeaseLifetime);
                when = when.ToLocalTime();
                Console.WriteLine("     DHCP Leased Life Time ................ : {0}",
                    when.ToString(lifeTimeFormat,System.Globalization.CultureInfo.CurrentCulture)
                );
            }
            Console.WriteLine();
        }
    }
}
Public Shared Sub DisplayUnicastAddresses() 

    Console.WriteLine("Unicast Addresses")
    Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
    Dim adapter As NetworkInterface
    For Each adapter In  adapters
        Dim adapterProperties As IPInterfaceProperties = adapter.GetIPProperties()
        Dim uniCast As UnicastIPAddressInformationCollection = adapterProperties.UnicastAddresses
        If uniCast.Count > 0 Then
            Console.WriteLine(adapter.Description)
            Dim lifeTimeFormat As String = "dddd, MMMM dd, yyyy  hh:mm:ss tt"
            Dim uni As UnicastIPAddressInformation
            For Each uni In  uniCast
                Dim [when] As DateTime
                
                Console.WriteLine("  Unicast Address ......................... : {0}", uni.Address)
                Console.WriteLine("     Prefix Origin ........................ : {0}", uni.PrefixOrigin)
                Console.WriteLine("     Suffix Origin ........................ : {0}", uni.SuffixOrigin)
                Console.WriteLine("     Duplicate Address Detection .......... : {0}", uni.DuplicateAddressDetectionState)
                
                ' Format the lifetimes as Sunday, February 16, 2003 11:33:44 PM
                ' if en-us is the current culture.
                ' Calculate the date and time at the end of the lifetimes.    
                [when] = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressValidLifetime)
                [when] = [when].ToLocalTime()
                Console.WriteLine("     Valid Life Time ...................... : {0}", [when].ToString(lifeTimeFormat, System.Globalization.CultureInfo.CurrentCulture))
                [when] = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressPreferredLifetime)
                [when] = [when].ToLocalTime()
                Console.WriteLine("     Preferred life time .................. : {0}", [when].ToString(lifeTimeFormat, System.Globalization.CultureInfo.CurrentCulture))
                
                [when] = DateTime.UtcNow + TimeSpan.FromSeconds(uni.DhcpLeaseLifetime)
                [when] = [when].ToLocalTime()
                Console.WriteLine("     DHCP Leased Life Time ................ : {0}", [when].ToString(lifeTimeFormat, System.Globalization.CultureInfo.CurrentCulture))
            Next uni
            Console.WriteLine()
        End If
    Next adapter

End Sub

備註

IP 位址分成兩個部分:前置詞和尾碼。 位址前置詞會識別 IP 位址的網路部分,而位址尾碼會識別主機部分。 前置詞是由全域授權單位指派,而後綴是由本機系統管理員指派。

MulticastIPAddressInformation 類別會 UnicastIPAddressInformation 使用此列舉。 當您擷取 物件的位址資訊時,會傳回這個類別的 NetworkInterface 實例。

適用於