Просмотр исходного кода

查询外网IP和地址

Signed-off-by: 高级CV工程师 <2535688890@qq.com>
高级CV工程师 7 месяцев назад
Родитель
Сommit
7ad37d4837
1 измененных файлов с 4 добавлено и 14 удалено
  1. 4 14
      Admin.NET/Admin.NET.Core/Utils/ComputerUtil.cs

+ 4 - 14
Admin.NET/Admin.NET.Core/Utils/ComputerUtil.cs

@@ -152,11 +152,11 @@ public static class ComputerUtil
     {
         try
         {
-            var url = "https://www.ip.cn/api/index?ip&type=0";
+            var url = "https://4.ipw.cn";
             var httpRemoteService = App.GetRequiredService<IHttpRemoteService>();
-            var str = httpRemoteService.GetAsStringAsync(url).GetAwaiter().GetResult();
-            var resp = JSON.Deserialize<IpCnResp>(str);
-            return resp.Ip + " " + resp.Address;
+            var ip = httpRemoteService.GetAsString(url);
+            var (ipLocation, _, _) = CommonUtil.GetIpAddress(ip);
+            return ip + " " + ipLocation;
         }
         catch
         {
@@ -246,16 +246,6 @@ public static class ComputerUtil
     }
 }
 
-/// <summary>
-/// IP信息
-/// </summary>
-public class IpCnResp
-{
-    public string Ip { get; set; }
-
-    public string Address { get; set; }
-}
-
 /// <summary>
 /// 内存信息
 /// </summary>