本文整理汇总了C#中System.Net.NetworkInformation.NetworkInterface.Supports方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkInterface.Supports方法的具体用法?C# NetworkInterface.Supports怎么用?C# NetworkInterface.Supports使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.NetworkInformation.NetworkInterface
的用法示例。
在下文中一共展示了NetworkInterface.Supports方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDeviceInfo
private string GetDeviceInfo(NetworkInterface adapter)
{
if (adapter == null)
{
return String.Empty;
}
IPInterfaceProperties properties = adapter.GetIPProperties();
StringBuilder infoBuilder = new StringBuilder();
infoBuilder.Append(adapter.Description + "\n");
infoBuilder.Append("=================================================\n");
infoBuilder.AppendFormat(" ID ......................... : {0}\n",
adapter.Id);
infoBuilder.AppendFormat(" Name ....................... : {0}\n",
adapter.Name);
infoBuilder.AppendFormat(" Interface type ............. : {0}\n",
adapter.NetworkInterfaceType);
infoBuilder.AppendFormat(" Physical Address ........... : {0}\n",
BitConverter.ToString(adapter.GetPhysicalAddress().GetAddressBytes()));
infoBuilder.AppendFormat(" Operational status ......... : {0}\n",
adapter.OperationalStatus);
infoBuilder.AppendFormat(" Speed ...................... : {0} Mb/s\n",
adapter.Speed / 1000000);
string versions = String.Empty;
// 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";
}
infoBuilder.AppendFormat(" IP version ................. : {0}\n",
versions);
infoBuilder.Append(GetIPAddresses(properties));
// The following information is not useful for loopback adapters.
if (adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback)
{
return infoBuilder.ToString();
}
infoBuilder.AppendFormat(" DNS suffix ................. : {0}\n",
properties.DnsSuffix);
if (adapter.Supports(NetworkInterfaceComponent.IPv4))
{
IPv4InterfaceProperties ipv4 = properties.GetIPv4Properties();
infoBuilder.AppendFormat(" Index ...................... : {0}\n",
ipv4.Index);
infoBuilder.AppendFormat(" MTU ........................ : {0}\n",
ipv4.Mtu);
infoBuilder.AppendFormat(" APIPA active ............... : {0}\n",
ipv4.IsAutomaticPrivateAddressingActive);
infoBuilder.AppendFormat(" APIPA enabled .............. : {0}\n",
ipv4.IsAutomaticPrivateAddressingEnabled);
infoBuilder.AppendFormat(" DHCP enabled ............... : {0}\n",
ipv4.IsDhcpEnabled);
infoBuilder.AppendFormat(" Forwarding enabled.......... : {0}\n",
ipv4.IsForwardingEnabled);
infoBuilder.AppendFormat(" Uses WINS .................. : {0}\n",
ipv4.UsesWins);
if (ipv4.UsesWins)
{
IPAddressCollection winsServers = properties.WinsServersAddresses;
if (winsServers.Count > 0)
{
foreach (IPAddress winsServer in winsServers)
{
infoBuilder.AppendFormat(" WINS Server ................ : {0}\n",
winsServer);
}
}
}
}
if (adapter.Supports(NetworkInterfaceComponent.IPv6))
{
IPv6InterfaceProperties ipv6 = properties.GetIPv6Properties();
infoBuilder.AppendFormat(" Index ...................... : {0}\n",
ipv6.Index);
infoBuilder.AppendFormat(" MTU ........................ : {0}\n",
ipv6.Mtu);
}
infoBuilder.AppendFormat(" DNS enabled ................ : {0}\n",
//.........这里部分代码省略.........
示例2: CreateLLDPPacket
/// <summary>
/// Generate LLDP packet for adapter
/// </summary>
/// <param name="adapter"></param>
private Packet CreateLLDPPacket(NetworkInterface adapter, PacketInfo pinfo)
{
Debug.IndentLevel = 2;
PhysicalAddress MACAddress = adapter.GetPhysicalAddress();
IPInterfaceProperties ipProperties = adapter.GetIPProperties();
IPv4InterfaceProperties ipv4Properties = null; // Ipv4
IPv6InterfaceProperties ipv6Properties = null;// Ipv6
// IPv6
if (adapter.Supports(NetworkInterfaceComponent.IPv6))
{
try
{
ipv6Properties = ipProperties.GetIPv6Properties();
}
catch (NetworkInformationException e)
{
// Adapter doesn't probably have IPv6 enabled
Debug.WriteLine(e.Message, EventLogEntryType.Warning);
}
}
// IPv4
if (adapter.Supports(NetworkInterfaceComponent.IPv4))
{
try
{
ipv4Properties = ipProperties.GetIPv4Properties();
}
catch (NetworkInformationException e)
{
// Adapter doesn't probably have IPv4 enabled
Debug.WriteLine(e.Message, EventLogEntryType.Warning);
}
}
// System description
Dictionary<string, string> systemDescription = new Dictionary<string, string>();
systemDescription.Add("OS", pinfo.OperatingSystem);
systemDescription.Add("Ver", pinfo.OperatingSystemVersion);
systemDescription.Add("User", pinfo.Username);
systemDescription.Add("Uptime", pinfo.Uptime);
// Port description
Dictionary<string, string> portDescription = new Dictionary<string, string>();
// adapter.Description is for example "Intel(R) 82579V Gigabit Network Connection"
// Registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\<number>\Description value
portDescription.Add("Vendor", adapter.Description);
/*
adapter.Id is GUID and can be found in several places:
In this example it is "{87423023-7191-4C03-A049-B8E7DBB36DA4}"
Registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
- \NetworkCards\<number>\ServiceName value (in same tree as adapter.Description!)
- \NetworkList\Nla\Cache\Intranet\<adapter.Id> key
- \NetworkList\Nla\Cache\Intranet\<domain>\<adapter.Id> key
Registry: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion
- \NetworkCards\<number>\ServiceName value
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007
{4D36E972-E325-11CE-BFC1-08002BE10318} == Network and Sharing Center -> viewing adapter's "Properties" and selecting "Device class GUID" from dropdown menu
{4D36E972-E325-11CE-BFC1-08002BE10318}\0007 == Network and Sharing Center -> viewing adapter's "Properties" and selecting "Driver key" from dropdown menu
- \NetCfgInstanceId value
- \Linkage\Export value (part of)
- \Linkage\FilterList value (part of)
- \Linkage\RootDevice value
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses\{ad498944-762f-11d0-8dcb-00c04fc3358c}\##?#PCI#VEN_8086&DEV_1503&SUBSYS_849C1043&REV_06#3&11583659&0&C8#{ad498944-762f-11d0-8dcb-00c04fc3358c}\#{87423023-7191-4C03-A049-B8E7DBB36DA4}\SymbolicLink value (part of)
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{ 4D36E972 - E325 - 11CE - BFC1 - 08002BE10318}\{ 87423023 - 7191 - 4C03 - A049 - B8E7DBB36DA4}
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\{ACB3F7A0-2E45-4435-854A-A4E120477E1D}\Connection\Name value (part of)
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\{ 87423023 - 7191 - 4C03 - A049 - B8E7DBB36DA4}
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\iphlpsvc\Parameters\Isatap\{ ACB3F7A0 - 2E45 - 4435 - 854A - A4E120477E1D}\InterfaceName value (part of)
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\<various names>\Linkage
- \Bind value (part of)
- \Export value (part of)
- \Route value (part of)
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\NetBT\Parameters\Interfaces\Tcpip_{87423023-7191-4C03-A049-B8E7DBB36DA4}
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Psched\Parameters\NdisAdapters\{87423023-7191-4C03-A049-B8E7DBB36DA4}
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\RemoteAccess\Interfaces\<number>\InterfaceName value
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Adapters\{87423023-7191-4C03-A049-B8E7DBB36DA4}\IpConfig value (part of)
IPv4 information:
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces\{87423023-7191-4C03-A049-B8E7DBB36DA4}
IPv6 information:
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters\Interfaces\{87423023-7191-4c03-a049-b8e7dbb36da4}
Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\WfpLwf\Parameters\NdisAdapters\{87423023-7191-4C03-A049-B8E7DBB36DA4}
//.........这里部分代码省略.........
示例3: NetworkInterface
internal NetworkInterface(NetworkInterfaceInformation info)
{
Information = info;
IPv4Index = -1;
IPv6Index = -1;
if (info.Supports(NetworkInterfaceComponent.IPv4))
{
IPv4Index = info.GetIPProperties().GetIPv4Properties().Index;
}
if (info.Supports(NetworkInterfaceComponent.IPv6))
{
IPv6Index = info.GetIPProperties().GetIPv6Properties().Index;
}
Index = Interlocked.Increment(ref NextIndex);
}
示例4: IfMtu
/// <summary>
/// Initializes a new instance of the <see cref="IfMtu"/> class.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="networkInterface">The network interface.</param>
public IfMtu(int index, NetworkInterface networkInterface)
: base("1.3.6.1.2.1.2.2.1.4.{0}", index)
{
if (networkInterface.Supports(NetworkInterfaceComponent.IPv4))
{
var pv4InterfaceProperties = networkInterface.GetIPProperties().GetIPv4Properties();
_data = new Integer32(pv4InterfaceProperties == null ? -1 : pv4InterfaceProperties.Mtu);
}
else
{
_data = new Integer32(networkInterface.GetIPProperties().GetIPv6Properties().Mtu);
}
}
示例5: NetAdapterInfo
internal NetAdapterInfo(NetworkInterface nic, int order)
{
m_Name = "{0}::{1}".Args(nic.Id, nic.Name);
m_Order = order;
m_Description = nic.Description;
m_ReceiveOnly = nic.IsReceiveOnly;
m_AdapterType = nic.NetworkInterfaceType.ToString();
m_Status = nic.OperationalStatus.ToString();
m_Speed = nic.Speed;
m_IPv4Support = nic.Supports( NetworkInterfaceComponent.IPv4 );
m_IPv6Support = nic.Supports( NetworkInterfaceComponent.IPv6 );
var addrs = nic.GetIPProperties().UnicastAddresses;
m_Addresses = new Registry<NetAddrInfo>();
var ord = 0;
foreach(var addr in addrs)
{
m_Addresses.Register( new NetAddrInfo(addr, ord) );
ord++;
}
}
示例6: TryGetLoopbackInterfaceIndex
public static bool TryGetLoopbackInterfaceIndex(NetworkInterface adapter, bool ipv4, out int interfaceIndex)
{
Fx.Assert(adapter != null, "adapter can't be null");
Fx.Assert(adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback, "adapter type must be loopback adapter");
interfaceIndex = -1;
bool result = false;
if (ipv4 && adapter.Supports(NetworkInterfaceComponent.IPv4))
{
interfaceIndex = NetworkInterface.LoopbackInterfaceIndex;
result = true;
}
else if (!ipv4 && adapter.Supports(NetworkInterfaceComponent.IPv6))
{
IPInterfaceProperties properties = adapter.GetIPProperties();
IPv6InterfaceProperties ipv6Properties = properties.GetIPv6Properties();
interfaceIndex = ipv6Properties.Index;
result = true;
}
return result;
}
示例7: getIpv6Addr
IEnumerable<IPAddress> getIpv6Addr(NetworkInterface nic)
{
if (nic.Supports(NetworkInterfaceComponent.IPv6))
{
IPInterfaceProperties ipprop = nic.GetIPProperties();
IPv6InterfaceProperties ipv6prop = ipprop.GetIPv6Properties();
foreach (UnicastIPAddressInformation addr in ipprop.UnicastAddresses)
{
if (addr.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
{
yield return addr.Address;
}
}
}
}
示例8: getIpv4AddrString
string getIpv4AddrString(NetworkInterface nic)
{
if (nic.Supports(NetworkInterfaceComponent.IPv4))
{
IPInterfaceProperties ipprop = nic.GetIPProperties();
IPv4InterfaceProperties ipv4prop = ipprop.GetIPv4Properties();
foreach (UnicastIPAddressInformation addr in ipprop.UnicastAddresses)
{
if (addr.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
return addr.Address.ToString();
}
}
}
return null;
}