当前位置:网站首页>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
边栏推荐
- 0x80070570 The file or directory is damaged and cannot be deleted (how to delete 0x80070091)
- 函数递归1.0
- Quickly learn database management
- [core]-ARMV7-A、ARMV8-A、ARMV9-A 架构简介「建议收藏」
- anaconda虚拟环境安装pytorch gpu版本
- Centos7 install mysql5.7 steps (graphical version)
- 分布式锁有哪些,怎么实现(分布式锁的三种实现的对比)
- 365天挑战LeetCode1000题——Day 044 最大层内元素和 层次遍历
- Google Chrome(谷歌浏览器)安装使用
- 这款悄然崛起的国产API接口管理工具,你一定要晓得
猜你喜欢
五种数据提交方式的优化
函数递归1.0
NameNode (NN) and SecondaryNameNode (2NN) working mechanism
Google Chrome(谷歌浏览器)安装使用
TOGAF10标准读书会第2场活动精彩继续,高光时刻回顾!
基于verilog的CRC校验(汇总)
Error EPERM operation not permitted, mkdir ‘Dsoftwarenodejsnode_cache_cacach两种解决办法
PyQt5快速开发与实战 9.7 UI层的自动化测试
Centos7 install mysql5.7
AMBA APB学习记录(AMBA 2.0)
随机推荐
这款悄然崛起的国产API接口管理工具,你一定要晓得
[RPI]树莓派监控温度及报警关机保护「建议收藏」
【Shader】Shader官方示例[通俗易懂]
行业案例 | 全面防护 赛宁助力能源工控安全建设
The cluster of safe mode
FastAPI 封装一个通用的response
[core]-ARMV7-A、ARMV8-A、ARMV9-A 架构简介「建议收藏」
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
The function of SQL GROUP BY dependence
计算机复试面试问题(计算机面试常见问题)
快速学完数据库管理
golang八股文整理(持续搬运)
AMBA APB学习记录(AMBA 3/4)
ECCV2022:在Transformer上进行递归,不增参数,计算量还少!
Exploring Plain Vision Transformer Backbones for Object Detection 论文阅读笔记
PHP序列化:eval
基于改进YOLOv5的轻量化航空目标检测方法
PyQt5快速开发与实战 10.1 获取城市天气预报
IDEA版Postman插件Restful Fast Request,细节到位,功能好用
[CPU Design Practice] Simple Pipeline CPU Design