ソースを参照

Ping工具添加检查外网连接;添加DNS列表(阿里DNS和百度DNS)

yuzhengyang 6 年 前
コミット
4ce2c6bbda

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

@@ -119,6 +119,7 @@
     <Compile Include="ModelUtils\ResultModels\ResultData.cs" />
     <Compile Include="ModelUtils\ResultModels\ResultData.cs" />
     <Compile Include="NetUtils\IPFormatter.cs" />
     <Compile Include="NetUtils\IPFormatter.cs" />
     <Compile Include="NetUtils\MacFormatter.cs" />
     <Compile Include="NetUtils\MacFormatter.cs" />
+    <Compile Include="NetUtils\NetAddressUtils\DNSTool.cs" />
     <Compile Include="NetUtils\NetConnectionInfo.cs" />
     <Compile Include="NetUtils\NetConnectionInfo.cs" />
     <Compile Include="NetUtils\NetFlowService.cs" />
     <Compile Include="NetUtils\NetFlowService.cs" />
     <Compile Include="NetUtils\NetflowTool.cs" />
     <Compile Include="NetUtils\NetflowTool.cs" />

+ 22 - 0
Azylee.Utils/Azylee.Core/NetUtils/NetAddressUtils/DNSTool.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Azylee.Core.NetUtils.NetAddressUtils
+{
+    /// <summary>
+    /// DNS 工具类
+    /// </summary>
+    public static class DNSTool
+    {
+        /// <summary>
+        /// 阿里DNS
+        /// </summary>
+        public const string AliDNS = "223.5.5.115";
+        /// <summary>
+        /// 百度DNS
+        /// </summary>
+        public const string BaiduDNS = "180.76.76.76";
+    }
+}

+ 31 - 0
Azylee.Utils/Azylee.Core/NetUtils/PingTool.cs

@@ -4,6 +4,7 @@
 //      desc:       工具描述
 //      desc:       工具描述
 //      Copyright (c) yuzhengyang. All rights reserved.
 //      Copyright (c) yuzhengyang. All rights reserved.
 //************************************************************************
 //************************************************************************
+using Azylee.Core.NetUtils.NetAddressUtils;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
@@ -12,8 +13,16 @@ using System.Text;
 
 
 namespace Azylee.Core.NetUtils
 namespace Azylee.Core.NetUtils
 {
 {
+    /// <summary>
+    /// Ping 工具
+    /// </summary>
     public class PingTool
     public class PingTool
     {
     {
+        /// <summary>
+        /// Ping 指定 IP 地址
+        /// </summary>
+        /// <param name="ip"></param>
+        /// <returns></returns>
         public static bool Ping(string ip)
         public static bool Ping(string ip)
         {
         {
             try
             try
@@ -24,5 +33,27 @@ namespace Azylee.Core.NetUtils
             }
             }
             catch { return false; }
             catch { return false; }
         }
         }
+        /// <summary>
+        /// 判断是否连接互联网
+        /// </summary>
+        /// <returns></returns>
+        public static bool Internet()
+        {
+            try
+            {
+                Ping _ping = new Ping();
+                PingReply _reply = _ping.Send(DNSTool.AliDNS);
+                if (_reply.Status == IPStatus.Success && _reply.Address.ToString() == DNSTool.AliDNS) return true;
+            }
+            catch { }
+            try
+            {
+                Ping _ping = new Ping();
+                PingReply _reply = _ping.Send(DNSTool.BaiduDNS);
+                if (_reply.Status == IPStatus.Success && _reply.Address.ToString() == DNSTool.BaiduDNS) return true;
+            }
+            catch { }
+            return false;
+        }
     }
     }
 }
 }

+ 1 - 1
Azylee.Utils/Azylee.Core/WindowsUtils/CMDUtils/CMDProcessTool.cs

@@ -1,6 +1,6 @@
 //************************************************************************
 //************************************************************************
 //      author:     yuzhengyang
 //      author:     yuzhengyang
-//      date:       2018.4.27 - 2018.5.30
+//      date:       2018.4.27 - 2019.4.7
 //      desc:       CMD 工具
 //      desc:       CMD 工具
 //      Copyright (c) yuzhengyang. All rights reserved.
 //      Copyright (c) yuzhengyang. All rights reserved.
 //************************************************************************
 //************************************************************************

+ 15 - 7
Azylee.Utils/Tests/Test.SysServiceApp/Form1.cs

@@ -1,5 +1,7 @@
-using Azylee.Core.WindowsUtils.AdminUtils;
+using Azylee.Core.NetUtils;
+using Azylee.Core.WindowsUtils.AdminUtils;
 using Azylee.Core.WindowsUtils.CMDUtils;
 using Azylee.Core.WindowsUtils.CMDUtils;
+using Azylee.WinformSkin.FormUI.Toast;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.ComponentModel;
@@ -20,21 +22,27 @@ namespace Test.SysServiceApp
 
 
         private void Form1_Load(object sender, EventArgs e)
         private void Form1_Load(object sender, EventArgs e)
         {
         {
-
+            var result = PingTool.Internet();
         }
         }
 
 
         private void button1_Click(object sender, EventArgs e)
         private void button1_Click(object sender, EventArgs e)
         {
         {
             var result = CMDServiceTool.Install(
             var result = CMDServiceTool.Install(
-                 "AccessSecurityService",
-                 @"F:\InstallServer\AccessSecurity.Service.exe",
-                 new WindowsAccountModel("", "administrator", "yzy123"));
+                 "AccessSecurity.Service",
+                 @"F:\AccessSecurity.Service\AccessSecurity.Service.exe",
+                 new WindowsAccountModel("", "administrator", "yzy"));
+
+            if (result) ToastForm.Display("安装服务", "成功");
+            else ToastForm.Display("安装服务", "失败", ToastForm.ToastType.error);
         }
         }
 
 
         private void button2_Click(object sender, EventArgs e)
         private void button2_Click(object sender, EventArgs e)
         {
         {
-            var result = CMDServiceTool.Uninstall("AccessSecurityService",
-                new WindowsAccountModel("", "administrator", "yzy123"));
+            var result = CMDServiceTool.Uninstall("AccessSecurity.Service",
+                new WindowsAccountModel("", "administrator", "yzy"));
+
+            if (result) ToastForm.Display("卸载服务", "成功");
+            else ToastForm.Display("卸载服务", "失败", ToastForm.ToastType.error);
         }
         }
     }
     }
 }
 }

+ 4 - 0
Azylee.Utils/Tests/Test.SysServiceApp/Test.SysServiceApp.csproj

@@ -78,6 +78,10 @@
       <Project>{88dc61fa-95f0-41b7-9d7d-ab0f3cbd169c}</Project>
       <Project>{88dc61fa-95f0-41b7-9d7d-ab0f3cbd169c}</Project>
       <Name>Azylee.Core</Name>
       <Name>Azylee.Core</Name>
     </ProjectReference>
     </ProjectReference>
+    <ProjectReference Include="..\..\Azylee.WinformSkin\Azylee.WinformSkin.csproj">
+      <Project>{D280C16F-FDE2-4647-BD76-3514F673426D}</Project>
+      <Name>Azylee.WinformSkin</Name>
+    </ProjectReference>
   </ItemGroup>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>
 </Project>