ソースを参照

添加网卡控制测试,已测试可支持XP、WIN10的网络启用和禁用。

yuzhengyang 7 年 前
コミット
0d122dc12d
22 ファイル変更1456 行追加6 行削除
  1. 1 0
      Azylee.Utils/Azylee.Core/Azylee.Core.csproj
  2. 137 0
      Azylee.Utils/Azylee.Core/NetUtils/NetworkAdapterTool.cs
  3. 71 5
      Azylee.Utils/Azylee.Core/WindowsUtils/InfoUtils/NetcardInfoTool.cs
  4. 57 0
      Azylee.Utils/Azylee.Ext.NetworkX/Azylee.Ext.NetworkX.csproj
  5. 51 0
      Azylee.Utils/Azylee.Ext.NetworkX/NetConLibUtils/NetConLibTool.cs
  6. 36 0
      Azylee.Utils/Azylee.Ext.NetworkX/Properties/AssemblyInfo.cs
  7. 16 0
      Azylee.Utils/Azylee.Utils.sln
  8. 0 1
      Azylee.Utils/Azylee.YeahWeb/Azylee.YeahWeb.csproj
  9. 4 0
      Azylee.Utils/Tests/Test.NetworkControl/FodyWeavers.xml
  10. 111 0
      Azylee.Utils/Tests/Test.NetworkControl/FodyWeavers.xsd
  11. 141 0
      Azylee.Utils/Tests/Test.NetworkControl/Form1.Designer.cs
  12. 219 0
      Azylee.Utils/Tests/Test.NetworkControl/Form1.cs
  13. 120 0
      Azylee.Utils/Tests/Test.NetworkControl/Form1.resx
  14. 21 0
      Azylee.Utils/Tests/Test.NetworkControl/Program.cs
  15. 36 0
      Azylee.Utils/Tests/Test.NetworkControl/Properties/AssemblyInfo.cs
  16. 71 0
      Azylee.Utils/Tests/Test.NetworkControl/Properties/Resources.Designer.cs
  17. 117 0
      Azylee.Utils/Tests/Test.NetworkControl/Properties/Resources.resx
  18. 30 0
      Azylee.Utils/Tests/Test.NetworkControl/Properties/Settings.Designer.cs
  19. 7 0
      Azylee.Utils/Tests/Test.NetworkControl/Properties/Settings.settings
  20. 130 0
      Azylee.Utils/Tests/Test.NetworkControl/Test.NetworkControl.csproj
  21. 75 0
      Azylee.Utils/Tests/Test.NetworkControl/app.manifest
  22. 5 0
      Azylee.Utils/Tests/Test.NetworkControl/packages.config

+ 1 - 0
Azylee.Utils/Azylee.Core/Azylee.Core.csproj

@@ -124,6 +124,7 @@
     <Compile Include="NetUtils\NetPacketTool.cs" />
     <Compile Include="NetUtils\NetProcessInfo.cs" />
     <Compile Include="NetUtils\NetProcessTool.cs" />
+    <Compile Include="NetUtils\NetworkAdapterTool.cs" />
     <Compile Include="NetUtils\PingTool.cs" />
     <Compile Include="ProcessUtils\ProcessInfoTool.cs" />
     <Compile Include="ProcessUtils\ProcessStarter.cs" />

+ 137 - 0
Azylee.Utils/Azylee.Core/NetUtils/NetworkAdapterTool.cs

@@ -0,0 +1,137 @@
+using Azylee.Core.DataUtils.StringUtils;
+using Azylee.Core.WindowsUtils.InfoUtils;
+using System;
+using System.Collections.Generic;
+using System.Management;
+
+namespace Azylee.Core.NetUtils
+{
+    /// <summary>
+    /// 网卡设备操作工具
+    /// </summary>
+    public static class NetcardControlTool
+    {
+        /// <summary>
+        /// 使用WMI获取网卡列表
+        /// </summary>
+        /// <returns></returns>
+        [Obsolete]
+        public static List<string> GetList()
+        {
+            List<string> list = new List<string>();
+            try
+            {
+                string manage = "SELECT * From Win32_NetworkAdapter";
+                ManagementObjectSearcher searcher = new ManagementObjectSearcher(manage);
+                ManagementObjectCollection collection = searcher.Get();
+
+                foreach (ManagementObject obj in collection)
+                {
+                    //foreach (var item in obj.Properties)
+                    //{
+                    //    Console.WriteLine(":::" + item.Name + ":::" + item.Value);
+                    //}
+                    list.Add(obj["Name"].ToString());
+                }
+            }
+            catch { }
+            return list;
+        }
+        /// <summary>
+        /// 获取设备对象(XP无设备ID,请勿使用此方法)
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        public static ManagementObject GetNetWorkByGuid(Guid id)
+        {
+            string netState = "SELECT * From Win32_NetworkAdapter";
+            try
+            {
+                ManagementObjectSearcher searcher = new ManagementObjectSearcher(netState);
+                ManagementObjectCollection collection = searcher.Get();
+
+                foreach (ManagementObject manage in collection)
+                {
+                    try
+                    {
+                        //string current_mac = NetCardInfoTool.ShortMac(manage["MacAddress"].ToString());
+                        //mac = NetCardInfoTool.ShortMac(mac);
+                        //if (current_mac == mac) return manage;
+                        Guid guid = Guid.NewGuid();
+                        if (manage["GUID"] != null && Guid.TryParse(manage["GUID"].ToString(), out guid))
+                        {
+                            if (guid == id) return manage;
+                        }
+                    }
+                    catch (Exception ex) { }
+                }
+            }
+            catch { }
+            return null;
+        }
+        /// <summary>
+        /// 获取设备对象
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        public static ManagementObject GetNetWorkByConnectId(string id)
+        {
+            string netState = "SELECT * From Win32_NetworkAdapter";
+            try
+            {
+                ManagementObjectSearcher searcher = new ManagementObjectSearcher(netState);
+                ManagementObjectCollection collection = searcher.Get();
+
+                foreach (ManagementObject manage in collection)
+                {
+                    try
+                    {
+                        if (manage["NetConnectionID"] != null && Str.Ok(id))
+                        {
+                            if (manage["NetConnectionID"].ToString() == id) return manage;
+                        }
+                    }
+                    catch (Exception ex) { }
+                }
+            }
+            catch { }
+            return null;
+        }
+        /// <summary>
+        /// 启用设备(不支持XP系统)
+        /// </summary>
+        /// <param name="network"></param>
+        /// <returns></returns>
+        public static bool Enable(ManagementObject network)
+        {
+            try
+            {
+                if (network != null)
+                {
+                    network.InvokeMethod("Enable", null);
+                    return true;
+                }
+            }
+            catch (Exception ex) { }
+            return false;
+        }
+        /// <summary>
+        /// 禁用设备(不支持XP系统)
+        /// </summary>
+        /// <param name="network"></param>
+        /// <returns></returns>
+        public static bool Disable(ManagementObject network)
+        {
+            try
+            {
+                if (network != null)
+                {
+                    network.InvokeMethod("Disable", null);
+                    return true;
+                }
+            }
+            catch (Exception ex) { }
+            return false;
+        }
+    }
+}

+ 71 - 5
Azylee.Utils/Azylee.Core/WindowsUtils/InfoUtils/NetcardInfoTool.cs

@@ -5,9 +5,11 @@
 //      Copyright (c) yuzhengyang. All rights reserved.
 //************************************************************************
 using Azylee.Core.DataUtils.CollectionUtils;
+using Azylee.Core.DataUtils.StringUtils;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.Linq;
 using System.Net;
 using System.Net.NetworkInformation;
 using System.Net.Sockets;
@@ -18,6 +20,29 @@ namespace Azylee.Core.WindowsUtils.InfoUtils
 {
     public class NetCardInfoTool
     {
+        public static List<NetworkInterface> NetworkInterfaces = new List<NetworkInterface>();
+        public static List<NetworkInterface> GetNetworkInterfaces()
+        {
+            try
+            {
+                NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
+                if (Ls.Ok(adapters))
+                {
+                    foreach (var item in adapters)
+                    {
+                        try
+                        {
+                            if (NetworkInterfaces.Any(x => x.Id == item.Id)) { }
+                            else { NetworkInterfaces.Add(item); }
+                        }
+                        catch { }
+                    }
+                }
+            }
+            catch { }
+            return NetworkInterfaces;
+        }
+
         /// <summary>
         /// 获取网卡信息
         /// 【名称、描述、物理地址(Mac)、Ip地址、网关地址】
@@ -28,7 +53,7 @@ namespace Azylee.Core.WindowsUtils.InfoUtils
             try
             {
                 List<Tuple<string, string, string, string, string>> result = new List<Tuple<string, string, string, string, string>>();
-                NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
+                List<NetworkInterface> adapters = GetNetworkInterfaces();
                 foreach (var item in adapters)
                 {
                     if (item.NetworkInterfaceType == NetworkInterfaceType.Ethernet || item.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
@@ -57,6 +82,46 @@ namespace Azylee.Core.WindowsUtils.InfoUtils
             }
         }
         /// <summary>
+        /// 获取网卡信息
+        /// 【id,名称、描述、物理地址(Mac)、Ip地址、网关地址】
+        /// </summary>
+        /// <returns></returns>
+        public static List<Tuple<string, string, string, string, string, Guid>> GetNetworkCardInfoId()
+        {
+            try
+            {
+                List<Tuple<string, string, string, string, string, Guid>> result = new List<Tuple<string, string, string, string, string, Guid>>();
+                List<NetworkInterface> adapters = GetNetworkInterfaces();
+                foreach (var item in adapters)
+                {
+                    if (item.NetworkInterfaceType == NetworkInterfaceType.Ethernet || item.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
+                    {
+                        string _name = item.Name.Trim();
+                        string _desc = item.Description.Trim();
+                        string _mac = item.GetPhysicalAddress().ToString();
+                        Guid _id = Guid.NewGuid();//随机一个ID(Empty可能导致重复性错误)
+                        Guid.TryParse(item.Id, out _id);
+                        //测试获取数据
+                        var x = item.GetIPProperties().UnicastAddresses;
+                        string _ip = item.GetIPProperties().UnicastAddresses.Count >= 1 ?
+                            item.GetIPProperties().UnicastAddresses[0].Address.ToString() : null;
+                        //更新IP为ipv4地址
+                        if (item.GetIPProperties().UnicastAddresses.Count > 0)
+                            _ip = item.GetIPProperties().UnicastAddresses[item.GetIPProperties().
+                                UnicastAddresses.Count - 1].Address.ToString();
+                        string _gateway = item.GetIPProperties().GatewayAddresses.Count >= 1 ?
+                            item.GetIPProperties().GatewayAddresses[0].Address.ToString() : null;
+                        result.Add(new Tuple<string, string, string, string, string, Guid>(_name, _desc, _mac, _ip, _gateway, _id));
+                    }
+                }
+                return result;
+            }
+            catch (NetworkInformationException e)
+            {
+                return null;
+            }
+        }
+        /// <summary>
         /// 获取网络连接状态
         /// </summary>
         /// <param name="dwFlag"></param>
@@ -94,7 +159,7 @@ namespace Azylee.Core.WindowsUtils.InfoUtils
                 foreach (var item in adapters)
                 {
                     string _mac = item.GetPhysicalAddress().ToString();
-                    if(_mac.ToUpper() == mac.ToUpper())
+                    if (_mac.ToUpper() == mac.ToUpper())
                         return item.OperationalStatus;
                 }
             }
@@ -175,11 +240,12 @@ namespace Azylee.Core.WindowsUtils.InfoUtils
         /// <returns></returns>
         public static string ShortMac(string s)
         {
-            if (!string.IsNullOrWhiteSpace(s))
+            try
             {
-                return s.Replace("-", "").Replace(":", "").ToLower();
+                if (Str.Ok(s)) return s.Replace(" ", "").Replace("-", "").Replace(":", "").ToLower();
             }
-            return "";
+            catch { }
+            return s;
         }
         /// <summary>
         /// 格式化MAC地址(大写、':' 分割)

+ 57 - 0
Azylee.Utils/Azylee.Ext.NetworkX/Azylee.Ext.NetworkX.csproj

@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{A320E11D-D771-4BBD-913F-DD0E87090943}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Azylee.Ext.NetworkX</RootNamespace>
+    <AssemblyName>Azylee.Ext.NetworkX</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="NetConLibUtils\NetConLibTool.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <COMReference Include="NETCONLib">
+      <Guid>{43E734CA-043D-4A70-9A2C-A8F254063D91}</Guid>
+      <VersionMajor>1</VersionMajor>
+      <VersionMinor>0</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>tlbimp</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>False</EmbedInteropTypes>
+    </COMReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 51 - 0
Azylee.Utils/Azylee.Ext.NetworkX/NetConLibUtils/NetConLibTool.cs

@@ -0,0 +1,51 @@
+using NETCONLib;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Azylee.Ext.NetworkX.NetConLibUtils
+{
+    /// <summary>
+    /// NetConLib 操作工具类
+    /// </summary>
+    public static class NetConLibTool
+    {
+        /// <summary>
+        /// 启用所有网络
+        /// </summary>
+        public static void Connect()
+        {
+            try
+            {
+                NetSharingManagerClass netSharingMgr = new NetSharingManagerClass();
+                INetSharingEveryConnectionCollection connections = netSharingMgr.EnumEveryConnection;
+                foreach (INetConnection connection in connections)
+                {
+                    try { connection.Connect(); } catch { }
+
+                    // // // //INetConnectionProps connProps = netSharingMgr.get_NetConnectionProps(connection);
+                    // // // //if (connProps.MediaType == tagNETCON_MEDIATYPE.NCM_LAN)
+                    // // // //    try { connection.Connect(); } catch { }
+                }
+            }
+            catch { }
+        }
+        /// <summary>
+        /// 禁用所有网络
+        /// </summary>
+        public static void Disconnect()
+        {
+            try
+            {
+                NetSharingManagerClass netSharingMgr = new NetSharingManagerClass();
+                INetSharingEveryConnectionCollection connections = netSharingMgr.EnumEveryConnection;
+                foreach (INetConnection connection in connections)
+                {
+                    try { connection.Disconnect(); } catch { }
+                }
+            }
+            catch { }
+        }
+    }
+}

+ 36 - 0
Azylee.Utils/Azylee.Ext.NetworkX/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("Azylee.Ext.NetworkX")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Azylee.Ext.NetworkX")]
+[assembly: AssemblyCopyright("Copyright ©  2019")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("a320e11d-d771-4bbd-913f-dd0e87090943")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+//通过使用 "*",如下所示:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 16 - 0
Azylee.Utils/Azylee.Utils.sln

@@ -37,6 +37,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.ImageToolTest", "Tests
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.Runrun", "Tests\Test.Runrun\Test.Runrun.csproj", "{37995B05-DB66-499F-B861-FB5451172E58}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.NetworkControl", "Tests\Test.NetworkControl\Test.NetworkControl.csproj", "{0497D55F-332B-40CC-A8C6-8D3AF98FEBAD}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Exts", "Exts", "{618CFF8A-0137-4E15-BC07-4E172B7FC5DA}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azylee.Ext.NetworkX", "Azylee.Ext.NetworkX\Azylee.Ext.NetworkX.csproj", "{A320E11D-D771-4BBD-913F-DD0E87090943}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -103,6 +109,14 @@ Global
 		{37995B05-DB66-499F-B861-FB5451172E58}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{37995B05-DB66-499F-B861-FB5451172E58}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{37995B05-DB66-499F-B861-FB5451172E58}.Release|Any CPU.Build.0 = Release|Any CPU
+		{0497D55F-332B-40CC-A8C6-8D3AF98FEBAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{0497D55F-332B-40CC-A8C6-8D3AF98FEBAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{0497D55F-332B-40CC-A8C6-8D3AF98FEBAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{0497D55F-332B-40CC-A8C6-8D3AF98FEBAD}.Release|Any CPU.Build.0 = Release|Any CPU
+		{A320E11D-D771-4BBD-913F-DD0E87090943}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A320E11D-D771-4BBD-913F-DD0E87090943}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A320E11D-D771-4BBD-913F-DD0E87090943}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A320E11D-D771-4BBD-913F-DD0E87090943}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -122,6 +136,8 @@ Global
 		{B251E246-9F9C-4AEC-9748-FBCFAD2381E1} = {9351FC10-E8D0-41BB-A813-0B5B3EA90605}
 		{E974326B-5950-4421-901A-5BA47FCC1270} = {9351FC10-E8D0-41BB-A813-0B5B3EA90605}
 		{37995B05-DB66-499F-B861-FB5451172E58} = {9351FC10-E8D0-41BB-A813-0B5B3EA90605}
+		{0497D55F-332B-40CC-A8C6-8D3AF98FEBAD} = {9351FC10-E8D0-41BB-A813-0B5B3EA90605}
+		{A320E11D-D771-4BBD-913F-DD0E87090943} = {618CFF8A-0137-4E15-BC07-4E172B7FC5DA}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {3A021A3E-4C98-47CD-B4E8-912E12611C2E}

+ 0 - 1
Azylee.Utils/Azylee.YeahWeb/Azylee.YeahWeb.csproj

@@ -83,6 +83,5 @@
   <ItemGroup>
     <None Include="packages.config" />
   </ItemGroup>
-  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 4 - 0
Azylee.Utils/Tests/Test.NetworkControl/FodyWeavers.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
+  <Costura />
+</Weavers>

+ 111 - 0
Azylee.Utils/Tests/Test.NetworkControl/FodyWeavers.xsd

@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+  <!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
+  <xs:element name="Weavers">
+    <xs:complexType>
+      <xs:all>
+        <xs:element name="Costura" minOccurs="0" maxOccurs="1">
+          <xs:complexType>
+            <xs:all>
+              <xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string">
+                <xs:annotation>
+                  <xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
+                </xs:annotation>
+              </xs:element>
+              <xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string">
+                <xs:annotation>
+                  <xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
+                </xs:annotation>
+              </xs:element>
+              <xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
+                <xs:annotation>
+                  <xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
+                </xs:annotation>
+              </xs:element>
+              <xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string">
+                <xs:annotation>
+                  <xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation>
+                </xs:annotation>
+              </xs:element>
+              <xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string">
+                <xs:annotation>
+                  <xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation>
+                </xs:annotation>
+              </xs:element>
+            </xs:all>
+            <xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean">
+              <xs:annotation>
+                <xs:documentation>This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.</xs:documentation>
+              </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="IncludeDebugSymbols" type="xs:boolean">
+              <xs:annotation>
+                <xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
+              </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="DisableCompression" type="xs:boolean">
+              <xs:annotation>
+                <xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
+              </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="DisableCleanup" type="xs:boolean">
+              <xs:annotation>
+                <xs:documentation>As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.</xs:documentation>
+              </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="LoadAtModuleInit" type="xs:boolean">
+              <xs:annotation>
+                <xs:documentation>Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.</xs:documentation>
+              </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean">
+              <xs:annotation>
+                <xs:documentation>Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.</xs:documentation>
+              </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="ExcludeAssemblies" type="xs:string">
+              <xs:annotation>
+                <xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
+              </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="IncludeAssemblies" type="xs:string">
+              <xs:annotation>
+                <xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
+              </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="Unmanaged32Assemblies" type="xs:string">
+              <xs:annotation>
+                <xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
+              </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="Unmanaged64Assemblies" type="xs:string">
+              <xs:annotation>
+                <xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation>
+              </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="PreloadOrder" type="xs:string">
+              <xs:annotation>
+                <xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation>
+              </xs:annotation>
+            </xs:attribute>
+          </xs:complexType>
+        </xs:element>
+      </xs:all>
+      <xs:attribute name="VerifyAssembly" type="xs:boolean">
+        <xs:annotation>
+          <xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
+        </xs:annotation>
+      </xs:attribute>
+      <xs:attribute name="VerifyIgnoreCodes" type="xs:string">
+        <xs:annotation>
+          <xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
+        </xs:annotation>
+      </xs:attribute>
+      <xs:attribute name="GenerateXsd" type="xs:boolean">
+        <xs:annotation>
+          <xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
+        </xs:annotation>
+      </xs:attribute>
+    </xs:complexType>
+  </xs:element>
+</xs:schema>

+ 141 - 0
Azylee.Utils/Tests/Test.NetworkControl/Form1.Designer.cs

@@ -0,0 +1,141 @@
+namespace Test.NetworkControl
+{
+    partial class Form1
+    {
+        /// <summary>
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows 窗体设计器生成的代码
+
+        /// <summary>
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.BtnEnable = new System.Windows.Forms.Button();
+            this.LbxNetworkList = new System.Windows.Forms.ListBox();
+            this.BtnDisable = new System.Windows.Forms.Button();
+            this.LbResult = new System.Windows.Forms.Label();
+            this.label1 = new System.Windows.Forms.Label();
+            this.BtnTest = new System.Windows.Forms.Button();
+            this.BtnLoad = new System.Windows.Forms.Button();
+            this.SuspendLayout();
+            // 
+            // BtnEnable
+            // 
+            this.BtnEnable.Location = new System.Drawing.Point(312, 12);
+            this.BtnEnable.Name = "BtnEnable";
+            this.BtnEnable.Size = new System.Drawing.Size(75, 23);
+            this.BtnEnable.TabIndex = 0;
+            this.BtnEnable.Text = "启用";
+            this.BtnEnable.UseVisualStyleBackColor = true;
+            this.BtnEnable.Click += new System.EventHandler(this.BtnEnable_Click);
+            // 
+            // LbxNetworkList
+            // 
+            this.LbxNetworkList.FormattingEnabled = true;
+            this.LbxNetworkList.ItemHeight = 12;
+            this.LbxNetworkList.Location = new System.Drawing.Point(12, 12);
+            this.LbxNetworkList.Name = "LbxNetworkList";
+            this.LbxNetworkList.Size = new System.Drawing.Size(274, 232);
+            this.LbxNetworkList.TabIndex = 1;
+            // 
+            // BtnDisable
+            // 
+            this.BtnDisable.Location = new System.Drawing.Point(312, 41);
+            this.BtnDisable.Name = "BtnDisable";
+            this.BtnDisable.Size = new System.Drawing.Size(75, 23);
+            this.BtnDisable.TabIndex = 2;
+            this.BtnDisable.Text = "禁用";
+            this.BtnDisable.UseVisualStyleBackColor = true;
+            this.BtnDisable.Click += new System.EventHandler(this.BtnDisable_Click);
+            // 
+            // LbResult
+            // 
+            this.LbResult.AutoSize = true;
+            this.LbResult.Location = new System.Drawing.Point(73, 259);
+            this.LbResult.Name = "LbResult";
+            this.LbResult.Size = new System.Drawing.Size(41, 12);
+            this.LbResult.TabIndex = 4;
+            this.LbResult.Text = "------";
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Location = new System.Drawing.Point(15, 259);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(41, 12);
+            this.label1.TabIndex = 5;
+            this.label1.Text = "输出:";
+            // 
+            // BtnTest
+            // 
+            this.BtnTest.Location = new System.Drawing.Point(312, 221);
+            this.BtnTest.Name = "BtnTest";
+            this.BtnTest.Size = new System.Drawing.Size(75, 23);
+            this.BtnTest.TabIndex = 6;
+            this.BtnTest.Text = "测试";
+            this.BtnTest.UseVisualStyleBackColor = true;
+            this.BtnTest.Click += new System.EventHandler(this.BtnTest_Click);
+            // 
+            // BtnLoad
+            // 
+            this.BtnLoad.Location = new System.Drawing.Point(312, 92);
+            this.BtnLoad.Name = "BtnLoad";
+            this.BtnLoad.Size = new System.Drawing.Size(75, 23);
+            this.BtnLoad.TabIndex = 7;
+            this.BtnLoad.Text = "刷新";
+            this.BtnLoad.UseVisualStyleBackColor = true;
+            this.BtnLoad.Click += new System.EventHandler(this.BtnLoad_Click);
+            // 
+            // Form1
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(406, 302);
+            this.Controls.Add(this.BtnLoad);
+            this.Controls.Add(this.BtnTest);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.LbResult);
+            this.Controls.Add(this.BtnDisable);
+            this.Controls.Add(this.LbxNetworkList);
+            this.Controls.Add(this.BtnEnable);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
+            this.MaximizeBox = false;
+            this.MinimizeBox = false;
+            this.Name = "Form1";
+            this.Text = "Form1";
+            this.Load += new System.EventHandler(this.Form1_Load);
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Button BtnEnable;
+        private System.Windows.Forms.ListBox LbxNetworkList;
+        private System.Windows.Forms.Button BtnDisable;
+        private System.Windows.Forms.Label LbResult;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.Button BtnTest;
+        private System.Windows.Forms.Button BtnLoad;
+    }
+}
+

+ 219 - 0
Azylee.Utils/Tests/Test.NetworkControl/Form1.cs

@@ -0,0 +1,219 @@
+using Azylee.Core.DataUtils.CollectionUtils;
+using Azylee.Core.IOUtils.DirUtils;
+using Azylee.Core.IOUtils.TxtUtils;
+using Azylee.Core.LogUtils.SimpleLogUtils;
+using Azylee.Core.NetUtils;
+using Azylee.Core.ThreadUtils.SleepUtils;
+using Azylee.Core.WindowsUtils.InfoUtils;
+using Azylee.Ext.NetworkX.NetConLibUtils;
+using NETCONLib;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Management;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Test.NetworkControl
+{
+    public partial class Form1 : Form
+    {
+        Log log = new Log();
+        List<Tuple<string, string, string, string, string>> MacList = null;
+        public Form1()
+        {
+            InitializeComponent();
+        }
+
+        private void Form1_Load(object sender, EventArgs e)
+        {
+            List<string> list111 = NetcardControlTool.GetList();
+            MacList = NetCardInfoTool.GetNetworkCardInfo();
+            if (Ls.Ok(MacList))
+            {
+                LbxNetworkList.Items.Clear();
+                foreach (var item in MacList) LbxNetworkList.Items.Add(item.Item2);
+            }
+        }
+        private void BtnLoad_Click(object sender, EventArgs e)
+        {
+            List<string> list111 = NetcardControlTool.GetList();
+            MacList = NetCardInfoTool.GetNetworkCardInfo();
+            if (Ls.Ok(MacList))
+            {
+                LbxNetworkList.Items.Clear();
+                foreach (var item in MacList) LbxNetworkList.Items.Add(item.Item2);
+            }
+        }
+
+        private void BtnEnable_Click(object sender, EventArgs e)
+        {
+            //var key = GetNetworkName();
+            //ManagementObject network = NetcardControlTool.GetNetWorkByConnectId(key);
+            //if (network != null)
+            //{
+            //    if (NetcardControlTool.Enable(network))
+            //    {
+            //        SetResult("成功");
+            //    }
+            //    else
+            //    {
+            //        SetResult("失败");
+            //    }
+            //}
+            NetConLibTool.Connect();
+        }
+
+        private void BtnDisable_Click(object sender, EventArgs e)
+        {
+            //var key = GetNetworkName();
+            //ManagementObject network = NetcardControlTool.GetNetWorkByConnectId(key);
+            //if (network != null)
+            //{
+            //    if (NetcardControlTool.Disable(network))
+            //    {
+            //        SetResult("成功");
+            //    }
+            //    else
+            //    {
+            //        SetResult("失败");
+            //    }
+            //}
+            NetConLibTool.Disconnect();
+        }
+        private string GetNetworkName()
+        {
+            int idx = LbxNetworkList.SelectedIndex;
+            if (idx >= 0 && MacList.Count > idx)
+            {
+                return MacList[idx].Item1;
+            }
+            return "";
+        }
+        private void SetResult(string s)
+        {
+            Invoke(new Action(() =>
+            {
+                LbResult.Text = s + Environment.NewLine + DateTime.Now;
+            }));
+        }
+        private void BtnTest_Click(object sender, EventArgs e)
+        {
+            Task.Factory.StartNew(() =>
+            {
+                try
+                {
+                    string manage = "SELECT * From Win32_NetworkAdapter";
+                    ManagementObjectSearcher searcher = new ManagementObjectSearcher(manage);
+                    ManagementObjectCollection collection = searcher.Get();
+                    foreach (ManagementObject obj in collection)
+                    {
+                        foreach (var item in obj.Properties)
+                        {
+                            log.i("   :::   " + item.Name + "   :::   " + item.Value);
+                        }
+                        log.i("==============================");
+                        log.i("==============================");
+                    }
+                }
+                catch { }
+                //====================================
+                log.v("STEP 1:获取网卡列表");
+                var list = NetCardInfoTool.GetNetworkCardInfoId();
+                if (Ls.ok(list))
+                {
+                    foreach (var item in list)
+                    {
+                        log.v($"{item.Item1} | {item.Item2} | {item.Item3} | {item.Item4} | {item.Item5}");
+                    }
+                }
+                //====================================
+                log.v("STEP 2:检查网卡状态");
+                if (Ls.ok(list))
+                {
+                    foreach (var item in list)
+                    {
+                        var status = NetCardInfoTool.GetOpStatus(item.Item3);
+                        log.v($"{item.Item1} | {item.Item2} | {item.Item3} | {status.ToString()}");
+                    }
+                }
+                //====================================
+                log.v("STEP 3:Ping 10.49.129.7");
+                bool pingflag1 = PingTool.Ping("10.49.129.7");
+                if (pingflag1) log.v("Ping 正常");
+                else log.v("Ping 异常");
+                //====================================
+                log.v("STEP 4:禁用网卡");
+                NetConLibTool.Disconnect();
+                //if (Ls.ok(list))
+                //{
+                //    foreach (var item in list)
+                //    {
+                //        ManagementObject network = NetcardControlTool.GetNetWorkByConnectId(item.Item1);
+                //        if (network != null)
+                //        {
+                //            bool disflag = NetcardControlTool.Disable(network);
+                //            log.v($"{item.Item1} | {item.Item2} | {item.Item3} | 禁用: {(disflag ? "成功" : "失败")}");
+                //        }
+                //    }
+                //}
+                //====================================
+                log.v("STEP 5:检查网卡状态");
+                if (Ls.ok(list))
+                {
+                    foreach (var item in list)
+                    {
+                        var status = NetCardInfoTool.GetOpStatus(item.Item3);
+                        log.v($"{item.Item1} | {item.Item2} | {item.Item3} | {status.ToString()}");
+                    }
+                }
+                //====================================
+                log.v("STEP 6:Ping 10.49.129.7");
+                bool pingflag2 = PingTool.Ping("10.49.129.7");
+                if (pingflag2) log.v("Ping 正常");
+                else log.v("Ping 异常");
+                //====================================
+                log.v("STEP 7:遍历启用网卡");
+                NetConLibTool.Connect();
+                //if (Ls.ok(list))
+                //{
+                //    foreach (var item in list)
+                //    {
+                //        ManagementObject network = NetcardControlTool.GetNetWorkByConnectId(item.Item1);
+                //        if (network != null)
+                //        {
+                //            bool disflag = NetcardControlTool.Enable(network);
+                //            log.v($"{item.Item1} | {item.Item2} | {item.Item3} | 启用: {(disflag ? "成功" : "失败")}");
+                //        }
+                //    }
+                //}
+                //====================================
+                log.v("STEP 8:等待一下");
+                Sleep.S(20);
+                //====================================
+                log.v("STEP 9:检查网卡状态");
+                if (Ls.ok(list))
+                {
+                    foreach (var item in list)
+                    {
+                        var status = NetCardInfoTool.GetOpStatus(item.Item3);
+                        log.v($"{item.Item1} | {item.Item2} | {item.Item3} | {status.ToString()}");
+                    }
+                }
+                //====================================
+                log.v("STEP 10:Ping 10.49.129.7");
+                bool pingflag3 = PingTool.Ping("10.49.129.7");
+                if (pingflag3) log.v("Ping 正常");
+                else log.v("Ping 异常");
+                //====================================
+
+                SetResult("测试结束,已生成测试报告");
+            });
+        }
+
+    }
+}

+ 120 - 0
Azylee.Utils/Tests/Test.NetworkControl/Form1.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 21 - 0
Azylee.Utils/Tests/Test.NetworkControl/Program.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+
+namespace Test.NetworkControl
+{
+    static class Program
+    {
+        /// <summary>
+        /// 应用程序的主入口点。
+        /// </summary>
+        [STAThread]
+        static void Main()
+        {
+            Application.EnableVisualStyles();
+            Application.SetCompatibleTextRenderingDefault(false);
+            Application.Run(new Form1());
+        }
+    }
+}

+ 36 - 0
Azylee.Utils/Tests/Test.NetworkControl/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("Test.NetworkControl")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Test.NetworkControl")]
+[assembly: AssemblyCopyright("Copyright ©  2019")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("0497d55f-332b-40cc-a8c6-8d3af98febad")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+// 方法是按如下所示使用“*”: :
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 71 - 0
Azylee.Utils/Tests/Test.NetworkControl/Properties/Resources.Designer.cs

@@ -0,0 +1,71 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     此代码由工具生成。
+//     运行时版本: 4.0.30319.42000
+//
+//     对此文件的更改可能导致不正确的行为,如果
+//     重新生成代码,则所做更改将丢失。
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Test.NetworkControl.Properties
+{
+
+
+    /// <summary>
+    ///   强类型资源类,用于查找本地化字符串等。
+    /// </summary>
+    // 此类是由 StronglyTypedResourceBuilder
+    // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
+    // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
+    // (以 /str 作为命令选项),或重新生成 VS 项目。
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    internal class Resources
+    {
+
+        private static global::System.Resources.ResourceManager resourceMan;
+
+        private static global::System.Globalization.CultureInfo resourceCulture;
+
+        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+        internal Resources()
+        {
+        }
+
+        /// <summary>
+        ///   返回此类使用的缓存 ResourceManager 实例。
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Resources.ResourceManager ResourceManager
+        {
+            get
+            {
+                if ((resourceMan == null))
+                {
+                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Test.NetworkControl.Properties.Resources", typeof(Resources).Assembly);
+                    resourceMan = temp;
+                }
+                return resourceMan;
+            }
+        }
+
+        /// <summary>
+        ///   覆盖当前线程的 CurrentUICulture 属性
+        ///   使用此强类型的资源类的资源查找。
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Globalization.CultureInfo Culture
+        {
+            get
+            {
+                return resourceCulture;
+            }
+            set
+            {
+                resourceCulture = value;
+            }
+        }
+    }
+}

+ 117 - 0
Azylee.Utils/Tests/Test.NetworkControl/Properties/Resources.resx

@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 30 - 0
Azylee.Utils/Tests/Test.NetworkControl/Properties/Settings.Designer.cs

@@ -0,0 +1,30 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:4.0.30319.42000
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Test.NetworkControl.Properties
+{
+
+
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
+    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
+    {
+
+        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+        public static Settings Default
+        {
+            get
+            {
+                return defaultInstance;
+            }
+        }
+    }
+}

+ 7 - 0
Azylee.Utils/Tests/Test.NetworkControl/Properties/Settings.settings

@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
+  <Profiles>
+    <Profile Name="(Default)" />
+  </Profiles>
+  <Settings />
+</SettingsFile>

+ 130 - 0
Azylee.Utils/Tests/Test.NetworkControl/Test.NetworkControl.csproj

@@ -0,0 +1,130 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="..\..\packages\Costura.Fody.3.2.1\build\Costura.Fody.props" Condition="Exists('..\..\packages\Costura.Fody.3.2.1\build\Costura.Fody.props')" />
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{0497D55F-332B-40CC-A8C6-8D3AF98FEBAD}</ProjectGuid>
+    <OutputType>WinExe</OutputType>
+    <RootNamespace>Test.NetworkControl</RootNamespace>
+    <AssemblyName>Test.NetworkControl</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <NuGetPackageImportStamp>
+    </NuGetPackageImportStamp>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup>
+    <ApplicationManifest>app.manifest</ApplicationManifest>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Costura, Version=3.2.1.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
+      <HintPath>..\..\packages\Costura.Fody.3.2.1\lib\net40\Costura.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Management" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Deployment" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Form1.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Form1.Designer.cs">
+      <DependentUpon>Form1.cs</DependentUpon>
+    </Compile>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <EmbeddedResource Include="Form1.resx">
+      <DependentUpon>Form1.cs</DependentUpon>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Properties\Resources.resx">
+      <Generator>ResXFileCodeGenerator</Generator>
+      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+      <SubType>Designer</SubType>
+    </EmbeddedResource>
+    <Compile Include="Properties\Resources.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Resources.resx</DependentUpon>
+    </Compile>
+    <None Include="app.manifest" />
+    <None Include="packages.config" />
+    <None Include="Properties\Settings.settings">
+      <Generator>SettingsSingleFileGenerator</Generator>
+      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+    </None>
+    <Compile Include="Properties\Settings.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Settings.settings</DependentUpon>
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
+    </Compile>
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\Azylee.Core\Azylee.Core.csproj">
+      <Project>{88dc61fa-95f0-41b7-9d7d-ab0f3cbd169c}</Project>
+      <Name>Azylee.Core</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\Azylee.Ext.NetworkX\Azylee.Ext.NetworkX.csproj">
+      <Project>{a320e11d-d771-4bbd-913f-dd0e87090943}</Project>
+      <Name>Azylee.Ext.NetworkX</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\Azylee.Jsons\Azylee.Jsons.csproj">
+      <Project>{de3ab999-96d3-4a53-a9f2-7409138d0333}</Project>
+      <Name>Azylee.Jsons</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\Azylee.YeahWeb\Azylee.YeahWeb.csproj">
+      <Project>{ccf7a654-b442-4db1-bb3b-0f8014c3237f}</Project>
+      <Name>Azylee.YeahWeb</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="FodyWeavers.xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <COMReference Include="NETCONLib">
+      <Guid>{43E734CA-043D-4A70-9A2C-A8F254063D91}</Guid>
+      <VersionMajor>1</VersionMajor>
+      <VersionMinor>0</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>tlbimp</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>False</EmbedInteropTypes>
+      <Private>True</Private>
+    </COMReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Import Project="..\..\packages\Fody.3.3.3\build\Fody.targets" Condition="Exists('..\..\packages\Fody.3.3.3\build\Fody.targets')" />
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+    <PropertyGroup>
+      <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
+    </PropertyGroup>
+    <Error Condition="!Exists('..\..\packages\Fody.3.3.3\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Fody.3.3.3\build\Fody.targets'))" />
+    <Error Condition="!Exists('..\..\packages\Costura.Fody.3.2.1\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Costura.Fody.3.2.1\build\Costura.Fody.props'))" />
+  </Target>
+</Project>

+ 75 - 0
Azylee.Utils/Tests/Test.NetworkControl/app.manifest

@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?>
+<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
+  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
+    <security>
+      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
+        <!-- UAC 清单选项
+             如果想要更改 Windows 用户帐户控制级别,请使用
+             以下节点之一替换 requestedExecutionLevel 节点。n
+        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
+        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
+        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
+
+            指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。
+            如果你的应用程序需要此虚拟化来实现向后兼容性,则删除此
+            元素。
+        -->
+        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+
+  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+    <application>
+      <!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的
+           Windows 版本的列表。取消评论适当的元素,Windows 将
+           自动选择最兼容的环境。 -->
+
+      <!-- Windows Vista -->
+      <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
+
+      <!-- Windows 7 -->
+      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
+
+      <!-- Windows 8 -->
+      <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
+
+      <!-- Windows 8.1 -->
+      <!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
+
+      <!-- Windows 10 -->
+      <!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
+
+    </application>
+  </compatibility>
+
+  <!-- 指示该应用程序可以感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
+       自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
+       选择加入。选择加入此设置的 Windows 窗体应用程序(目标设定为 .NET Framework 4.6 )还应
+       在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。-->
+  <!--
+  <application xmlns="urn:schemas-microsoft-com:asm.v3">
+    <windowsSettings>
+      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
+    </windowsSettings>
+  </application>
+  -->
+
+  <!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->
+  <!--
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity
+          type="win32"
+          name="Microsoft.Windows.Common-Controls"
+          version="6.0.0.0"
+          processorArchitecture="*"
+          publicKeyToken="6595b64144ccf1df"
+          language="*"
+        />
+    </dependentAssembly>
+  </dependency>
+  -->
+
+</assembly>

+ 5 - 0
Azylee.Utils/Tests/Test.NetworkControl/packages.config

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="Costura.Fody" version="3.2.1" targetFramework="net40" />
+  <package id="Fody" version="3.3.3" targetFramework="net40" developmentDependency="true" />
+</packages>