SuffixOrigin 枚举
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定如何定位 IP 地址主机后缀。
public enum class SuffixOrigin
public enum SuffixOrigin
type SuffixOrigin =
Public Enum SuffixOrigin
- 继承
字段
LinkLayerAddress | 4 | 后缀是链接本地后缀。 |
Manual | 1 | 后缀是手动配置的。 |
OriginDhcp | 3 | 后缀是由动态主机配置协议 (DHCP) 服务器提供的。 |
Other | 0 | 后缀是用未指定的源定位的。 |
Random | 5 | 后缀是随机分配的。 |
WellKnown | 2 | 后缀是已知后缀。 已知后缀在标准跟踪请求注释 (RFC) 文档中指定并由 Internet 编号分配管理机构 (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 地址的网络部分,地址后缀标识主机部分。 前缀由全局颁发机构分配,后缀由本地系统管理员分配。
此枚举由 UnicastIPAddressInformation 类使用。 检索 对象的单播地址信息时,将返回此类的 NetworkInterface 实例。