当前位置:网站首页>C#获得网卡信息 NetworkInterface IPInterfaceProperties
C#获得网卡信息 NetworkInterface IPInterfaceProperties
2022-07-31 12:54:00 【黄昏和星空】
System.Net.NetworkInformation下的
1:NetworkInterface类,提供网络适配器的配置和统计信息。
可以通过它检测本机配置了多少网卡,哪些网络连接可用,获得网卡的MAC地址和速度等。
此类封装本地计算机上的网络接口(也称作适配器)的数据。不需创建此类的实例;GetAllNetworkInterfaces 方法返回一个数组,对于本地计算机上的每个网络接口,该数组中都包含一个此类的实例。
2:IPInterfaceProperties类 提供有关支持 Internet 协议版本 4 (IPv4) 或 Internet 协议版本 6 (IPv6) 的网络接口的信息。
此类可用于访问支持 IPv4 或 IPv6 的网络接口的配置和地址信息。不要创建此类的实例,这些实例将由 GetIPProperties 方法返回。
若要访问 IPv4 特定属性,请使用 GetIPv4Properties 方法返回的对象。若要访问 IPv6 特定属性,请使用 GetIPv6Properties 方法返回的对象
void Start () {
//网卡信息类
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adap in adapters)
{
Debug.Log("CardName::" + adap.Name + " /Speed::" + adap.Speed + " /MAC::" + BitConverter.ToString(adap.GetPhysicalAddress().GetAddressBytes()));
IPInterfaceProperties ipProperties = adap.GetIPProperties();
GatewayIPAddressInformationCollection gateways = ipProperties.GatewayAddresses;
foreach (var tmp in gateways)
{
Debug.Log("Gateway>>>"+tmp.Address);
}
IPAddressCollection dnsAddress = ipProperties.DnsAddresses;
foreach (IPAddress tmp in dnsAddress)
{
Debug.Log("DNS>>>" + BitConverter.ToString(tmp.GetAddressBytes()));
}
}
}
//output
NetworkInterface>>> https://msdn.microsoft.com/zh-cn/library/system.net.networkinformation.networkinterface%28v=vs.110%29.aspx
IPInterfaceProperties>>> https://msdn.microsoft.com/zh-cn/library/system.net.networkinformation.ipinterfaceproperties%28v=vs.110%29.aspx
边栏推荐
猜你喜欢

Exploring Plain Vision Transformer Backbones for Object Detection Paper Reading Notes

CentOS7 installation MySQL graphic detailed tutorial

攻防演练丨赛宁红方管控平台走进广东三地 助力数字政府网络安全建设

一文吃透哈希表

PyQt5 rapid development and actual combat 10.1 Get city weather forecast

Centos7 install mysql5.7

TOGAF10标准读书会第2场活动精彩继续,高光时刻回顾!

Anaconda安装labelImg图像标注软件

365-day challenge LeetCode1000 questions - Day 044 Maximum element in the layer and level traversal

centos7安装mysql5.7
随机推荐
WPF中TabControl动态获取当前选中的TabItem
Full GC (Ergonomics)排查分析
matlab as(assert dominance)
[core]-ARMV7-A、ARMV8-A、ARMV9-A 架构简介「建议收藏」
基于改进YOLOv5的轻量化航空目标检测方法
LRU缓存[线性表 -> 链表 -> hash定位 -> 双向链表]
STM32——软件SPI控制AD7705[通俗易懂]
阿里三面:MQ 消息丢失、重复、积压问题,怎么解决?
log4j2的使用
ASM module in SAP Ecommerce Cloud Spartacus UI and Accelerator UI
Optimization of five data submission methods
Getting started with jmeter performance testing steps (performance testing tool jmeter)
sqlalchemy determines whether a field of type array has at least one consistent data with an array
0x80070570文件或目录损坏且无法删除(0x80070091怎么删除)
通过斐波那契数再谈函数递归2.0
Three-Phase PWM Rectifier Predictive Direct Power Control
Basic use of dosbox [easy to understand]
手撕Verilog PWM呼吸灯
P5019 [NOIP2018 提高组] 铺设道路
PyQt5 rapid development and actual combat 10.2 compound interest calculation && 10.3 refresh blog clicks