Skip to content

Commit

Permalink
去除重复IP地址
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Dec 2, 2024
1 parent c580ebe commit 4d2fc34
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions NewLife.Core/Net/NetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,22 @@ public static IEnumerable<IPAddress> GetIPs()

// 带网关的接口地址很重要,优先返回
// Linux下不支持PrefixOrigin
var ips = dic.OrderByDescending(e => e.Value)
//.ThenByDescending(e => e.Key.PrefixOrigin == PrefixOrigin.Dhcp || e.Key.PrefixOrigin == PrefixOrigin.Manual)
.Select(e => e.Key.Address).ToList();
//var ips = dic.OrderByDescending(e => e.Value)
// //.ThenByDescending(e => e.Key.PrefixOrigin == PrefixOrigin.Dhcp || e.Key.PrefixOrigin == PrefixOrigin.Manual)
// .Select(e => e.Key.Address).ToList();

// 去除重复IP地址
var ips = new List<IPAddress>();
var hash = new List<String>();
foreach (var item in dic.OrderByDescending(e => e.Value))
{
var address = item.Key.Address + "";
if (!hash.Contains(address))
{
ips.Add(item.Key.Address);
hash.Add(address);
}
}

return ips;
}
Expand Down

0 comments on commit 4d2fc34

Please sign in to comment.