瀏覽代碼

!1275 【轻量级 PR】:修复外网地址无法访问时导致系统监控整体信息无法获取的问题
Merge pull request !1275 from inypeacock/N/A

zuohuaijun 1 年之前
父節點
當前提交
b61bc7d38d
共有 1 個文件被更改,包括 10 次插入3 次删除
  1. 10 3
      Admin.NET/Admin.NET.Core/Util/ComputerUtil.cs

+ 10 - 3
Admin.NET/Admin.NET.Core/Util/ComputerUtil.cs

@@ -148,9 +148,16 @@ public static class ComputerUtil
     public static string GetIpFromOnline()
     {
         var url = "https://www.ip.cn/api/index?ip&type=0";
-        var str = url.GetAsStringAsync().GetAwaiter().GetResult();
-        var resp = JSON.Deserialize<IpCnResp>(str);
-        return resp.Ip + " " + resp.Address;
+        try
+        {
+            var str = url.GetAsStringAsync().GetAwaiter().GetResult();
+            var resp = JSON.Deserialize<IpCnResp>(str);
+            return resp.Ip + " " + resp.Address;
+        }
+        catch
+        {
+            return "";
+        }
     }
 
     public static bool IsUnix()