IPAddressInformation.Address 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取 Internet 协议 (IP) 地址。
public:
abstract property System::Net::IPAddress ^ Address { System::Net::IPAddress ^ get(); };
public abstract System.Net.IPAddress Address { get; }
member this.Address : System.Net.IPAddress
Public MustOverride ReadOnly Property Address As IPAddress
属性值
IPAddress 实例,它包含接口的 IP 地址。
示例
下面的代码示例显示本地计算机上网络接口的多播地址。
void DisplayMulticastAddresses()
{
int count = 0;
Console::WriteLine( "Multicast Addresses" );
array<NetworkInterface^>^adapters = NetworkInterface::GetAllNetworkInterfaces();
System::Collections::IEnumerator^ myEnum15 = adapters->GetEnumerator();
while ( myEnum15->MoveNext() )
{
NetworkInterface ^ adapter = safe_cast<NetworkInterface ^>(myEnum15->Current);
IPInterfaceProperties ^ adapterProperties = adapter->GetIPProperties();
MulticastIPAddressInformationCollection ^ multiCast = adapterProperties->MulticastAddresses;
if ( multiCast->Count > 0 )
{
Console::WriteLine( adapter->Description );
System::Collections::IEnumerator^ myEnum16 = multiCast->GetEnumerator();
while ( myEnum16->MoveNext() )
{
MulticastIPAddressInformation ^ multi = safe_cast<MulticastIPAddressInformation ^>(myEnum16->Current);
Console::WriteLine( " Multicast Address ....................... : {0} {1} {2}",
multi->Address, multi->IsTransient ? "Transient" : "",
multi->IsDnsEligible ? "DNS Eligible" : "" );
count++;
}
Console::WriteLine();
}
}
if (count == 0)
{
Console::WriteLine(" No multicast addresses were found.");
Console::WriteLine();
}
}
public static void DisplayMulticastAddresses()
{
int count = 0;
Console.WriteLine("Multicast Addresses");
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{
IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
MulticastIPAddressInformationCollection multiCast = adapterProperties.MulticastAddresses;
if (multiCast.Count > 0)
{
Console.WriteLine(adapter.Description);
foreach (IPAddressInformation multi in multiCast)
{
Console.WriteLine(" Multicast Address ....................... : {0} {1} {2}",
multi.Address,
multi.IsTransient ? "Transient" : "",
multi.IsDnsEligible ? "DNS Eligible" : ""
);
count++;
}
Console.WriteLine();
}
}
if (count == 0)
{
Console.WriteLine(" No multicast addressses were found.");
Console.WriteLine();
}
}
Public Shared Sub DisplayMulticastAddresses()
Dim count as Integer = 0
Console.WriteLine("Multicast Addresses")
Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
Dim adapter As NetworkInterface
For Each adapter In adapters
Dim adapterProperties As IPInterfaceProperties = adapter.GetIPProperties()
Dim multiCast As MulticastIPAddressInformationCollection = adapterProperties.MulticastAddresses
If multiCast.Count > 0 Then
Console.WriteLine(adapter.Description)
Dim multi As IPAddressInformation
For Each multi In multiCast
Console.WriteLine(" Multicast Address ....................... : {0} {1} {2}", multi.Address, IIf(multi.IsTransient, "Transient", ""), IIf(multi.IsDnsEligible, "DNS Eligible", ""))
'TODO: For performance reasons this should be changed to nested IF statements
'TODO: For performance reasons this should be changed to nested IF statements
count += 1
Next multi
Console.WriteLine()
End If
Next adapter
if count = 0 then
Console.WriteLine(" No multicast addresses were found.")
Console.WriteLine()
End if
End Sub
注解
IP 地址唯一标识网络上的接口。