本文整理汇总了C#中System.Net.NetworkInformation.NetworkInterface类的典型用法代码示例。如果您正苦于以下问题:C# NetworkInterface类的具体用法?C# NetworkInterface怎么用?C# NetworkInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetworkInterface类属于System.Net.NetworkInformation命名空间,在下文中一共展示了NetworkInterface类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ShowNetworkInterfaces
public static void ShowNetworkInterfaces()
{
IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
Console.WriteLine("Interface information for {0}.{1} ",
computerProperties.HostName, computerProperties.DomainName);
if (nics == null || nics.Length < 1)
{
Console.WriteLine(" No network interfaces found.");
return;
}
Console.WriteLine(" Number of interfaces .................... : {0}", nics.Length);
foreach (NetworkInterface adapter in nics)
{
IPInterfaceProperties properties = adapter.GetIPProperties();
Console.WriteLine();
Console.WriteLine(adapter.Description);
Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length,'='));
Console.WriteLine(" Interface type .......................... : {0}", adapter.NetworkInterfaceType);
Console.WriteLine(" Physical Address ........................ : {0}",
adapter.GetPhysicalAddress().ToString());
Console.WriteLine(" Operational status ...................... : {0}",
adapter.OperationalStatus);
string versions ="";
// Create a display string for the supported IP versions.
if (adapter.Supports(NetworkInterfaceComponent.IPv4))
{
versions = "IPv4";
}
if (adapter.Supports(NetworkInterfaceComponent.IPv6))
{
if (versions.Length > 0)
{
versions += " ";
}
versions += "IPv6";
}
Console.WriteLine(" IP version .............................. : {0}", versions);
ShowIPAddresses(properties);
// The following information is not useful for loopback adapters.
if (adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback)
{
continue;
}
Console.WriteLine(" DNS suffix .............................. : {0}",
properties.DnsSuffix);
string label;
if (adapter.Supports(NetworkInterfaceComponent.IPv4))
{
IPv4InterfaceProperties ipv4 = properties.GetIPv4Properties();
Console.WriteLine(" MTU...................................... : {0}", ipv4.Mtu);
if (ipv4.UsesWins)
{
IPAddressCollection winsServers = properties.WinsServersAddresses;
if (winsServers.Count > 0)
{
label = " WINS Servers ............................ :";
ShowIPAddresses(label, winsServers);
}
}
}
Console.WriteLine(" DNS enabled ............................. : {0}",
properties.IsDnsEnabled);
Console.WriteLine(" Dynamically configured DNS .............. : {0}",
properties.IsDynamicDnsEnabled);
Console.WriteLine(" Receive Only ............................ : {0}",
adapter.IsReceiveOnly);
Console.WriteLine(" Multicast ............................... : {0}",
adapter.SupportsMulticast);
ShowInterfaceStatistics(adapter);
Console.WriteLine();
}
开发者ID:.NET开发者,项目名称:System.Net.NetworkInformation,代码行数:79,代码来源:NetworkInterface
注:本文中的System.Net.NetworkInformation.NetworkInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论