winform C#获得Mac地址,IP地址,子网掩码,默认网关的实例
作者:jingxian 时间:2021-06-28 20:45:50
1. 添加程序集
2. 引入命名空间
using System.Management;
3. 方法
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection nics = mc.GetInstances();
foreach (ManagementObject nic in nics)
{
if (Convert.ToBoolean(nic["ipEnabled"]) == true)
{
string mac = nic["MacAddress"].ToString();//Mac地址
string ip = (nic["IPAddress"] as String[])[0];//IP地址
string ipsubnet = (nic["IPSubnet"] as String[])[0];//子网掩码
string ipgateway = (nic["DefaultIPGateway"] as String[])[0];//默认网关
}
}
标签:ip,子网掩码,默认网关
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
基于SSM实现学生管理系统
2023-11-24 18:17:39
![](https://img.aspxhome.com/file/2023/0/59190_0s.jpg)
使用 Spring Boot 2.0 + WebFlux 实现 RESTful API功能
2023-12-22 19:51:03
![](https://img.aspxhome.com/file/2023/1/96521_0s.png)
Android 实现获取手机里面的所有图片详解及实例
2023-09-13 14:55:14
一文解决springboot打包成jar文件无法正常运行的问题
2021-11-03 14:54:28
![](https://img.aspxhome.com/file/2023/0/67120_0s.png)
解决java.util.NoSuchElementException异常的问题
2023-02-10 08:26:46
![](https://img.aspxhome.com/file/2023/3/93153_0s.jpg)
解决AndroidStudio无法运行java中的mian方法问题
2021-06-17 02:57:32
![](https://img.aspxhome.com/file/2023/3/89533_0s.png)
深入解析Java多态进阶学习
2022-05-16 16:06:55
![](https://img.aspxhome.com/file/2023/9/73039_0s.jpg)
SpringBoot2 参数管理实践之入参出参与校验的方式
2022-12-25 02:44:30
spring boot使用logback日志级别打印控制操作
2021-08-11 07:40:03
Java逃逸分析详解及代码示例
2021-05-29 15:23:15
Java结构型设计模式中建造者模式示例详解
2023-04-24 13:37:31
![](https://img.aspxhome.com/file/2023/6/60286_0s.png)
C# Socket 发送&接收&返回 简单应用实例
2022-09-18 20:08:20
Java的引用类型常用的四种方法
2023-11-29 14:05:24
![](https://img.aspxhome.com/file/2023/9/60349_0s.png)
Spring注解配置IOC,DI的方法详解
2023-10-18 14:06:23
![](https://img.aspxhome.com/file/2023/1/77131_0s.png)
Spring Boot实现文件上传下载
2021-11-22 21:19:36
![](https://img.aspxhome.com/file/2023/3/71693_0s.jpg)
Socket结合线程池使用实现客户端和服务端通信demo
2023-01-21 20:23:50
![](https://img.aspxhome.com/file/2023/5/86835_0s.jpg)
java实现将域名解析成ip示例
2021-11-20 10:33:33
深入剖析Java中String类的concat方法
2023-06-02 07:07:13
C#值类型、引用类型中的Equals和==的区别浅析
2022-09-05 23:04:24
![](https://img.aspxhome.com/file/2023/3/98283_0s.png)
Android开发新手常见的10个误区
2021-07-30 02:14:10