当前位置:网站首页>C# 32. Select a network card from the static class implementation drop-down box
C# 32. Select a network card from the static class implementation drop-down box
2022-06-09 18:35:00 【lljss2020】
//NetIf.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.NetworkInformation;
namespace Xxxxx
{
class NetIf
{
public struct NetIfType
{
public string netIf;
public string Ip;
}
public static List<NetIfType> NetIfList = new List<NetIfType>();
public static int selectNetIf = 0;
public static List<NetIfType> GetNetIf()
{
List<NetIfType> listStr = new List<NetIfType>();
// Get all network card information
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
// Determine whether it is an Ethernet card
//Wireless80211 wireless network adapter Ppp broadband connection
//Ethernet Ethernet card
if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
// Get Ethernet card network interface information
IPInterfaceProperties ip = adapter.GetIPProperties();
// Get unicast address set
UnicastIPAddressInformationCollection ipCollection = ip.UnicastAddresses;
foreach (UnicastIPAddressInformation ipadd in ipCollection)
{
//InterNetwork IPV4 Address InterNetworkV6 IPV6 Address
//Max MAX Address
if (ipadd.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
listStr.Add(new NetIfType()
{
netIf = adapter.Description,
Ip = ipadd.Address.ToString()
});
}
}
}
}
return listStr;
}
// Select local on network card IP
public static string GetLocalIp(int index)
{
if (index>= 0)
{
return NetIfList[index].Ip;
}
else
{
return null;
}
}
}
}
private void comboBoxNetIf_DropDown(object sender, EventArgs e)
{
NetIf.NetIfList.Clear();
NetIf.NetIfList = NetIf.GetNetIf();
comboBoxNetIf.Items.Clear();
foreach (NetIf.NetIfType m in NetIf.NetIfList)
{
comboBoxNetIf.Items.Add(m.netIf);
}
}
// In Africa UI In the thread
private void UserThread()
{
string localIp = null;
int flag;
Invoke((EventHandler)(delegate
{
NetIf.selectNetIf = comboBoxNetIf.SelectedIndex;
}));
localIp = NetIf.GetLocalIp(NetIf.selectNetIf);
.......
}
The actual effect :
边栏推荐
- 聊聊 延时消息的 6种 实现方案
- 【操作教程】如何正确使用海康demo工具配置通道上线?
- 【MySQL字符串数据类型优化】char和varchar的区别
- 220609-R
- Process control -- > > process termination
- RPC framework in simple terms
- What is the difference between MySQL delete, truncate and drop
- MySQL启动失败的原因是什么及如何解决
- Talk about MQ technology selection
- Transformer模型新SOTA--fully attentional networks (FANs) 学习笔记
猜你喜欢

Do your filial duty to make an old people's fall prevention alarm system for your family

SQL题目整理

AD PCB画图透明度

C# 29. textbox始终显示最后一行

Inspur cs5280h raid scheme details

Management of free memory

深度学习与CV教程(13) | 目标检测 (SSD,YOLO系列)

直播预告 | 在阿里云 ESSD 云盘上部署 PolarDB for PostgreSQL 集群

gcc编译demo+Makefile使用

11年程序员给本科、研究生应届生以及准备从事后台开发同学的建议,学习进阶之路
随机推荐
GEE|求NDVI改进版
CAM350检查gerber与钻孔文件
C# 30. 字符串截取
WSL attaching USB flash disk
Transformer模型新SOTA--fully attentional networks (FANs) 学习笔记
What is the reason for MySQL startup failure and how to solve it
【操作教程】如何正确使用海康demo工具配置通道上线?
Squeeze and exception networks learning notes
AD PCB画图透明度
What should I do if the RTMP stream address returned by easynvr non demand streaming cannot be played?
日常2琐事^_^
Principle and implementation of avoiding group panic and load balancing
Golang Foundation (4)
解决swap file .swp already exists 问题
期货公司 开户,安全开户流程?
mysql版本驱动问题
Analysis of C language [advanced] paid knowledge [II]
Introduction to Multivariate Statistics
转:彼得·德鲁克:什么样的老师才是真正的老师?
[high level knowledge] epoll implementation principle of user mode protocol stack