/// <summary> /// 检测网卡是否选择正确 /// </summary> /// <returns></returns> private bool CheckAdapterState() { if (GlobleSetting.Adapter.Equals("Null")) { return(false); } try { var nd = new NetworkDevices(); var devices = nd.GetDevices(); if (devices != null) { if (!devices.Any(e => e.Name.Equals(GlobleSetting.Adapter))) { return(false); } } return(true); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }
/// <summary> /// 读取可用的网卡列表 /// </summary> private void ReadAdapterList() { try { var nd = new NetworkDevices(); var devices = nd.GetDevices(); if (devices != null) { /* * foreach (DevicesData device in devices) * { * adapterList.Items.Add(device); * } * */ adapterList.DataSource = devices; if (GlobleSetting.Adapter.Equals("Null")) { //如果为设置网卡,则默认选取第一个 adapterList.SelectedIndex = -1; } else { if (devices.Any(e => e.Name.Equals(GlobleSetting.Adapter))) { adapterList.SelectedValue = GlobleSetting.Adapter; } else { adapterList.SelectedIndex = -1; } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }