diff --git a/DnsServerCore/WebServiceDashboardApi.cs b/DnsServerCore/WebServiceDashboardApi.cs index ca7e8b99..e7522346 100644 --- a/DnsServerCore/WebServiceDashboardApi.cs +++ b/DnsServerCore/WebServiceDashboardApi.cs @@ -621,22 +621,33 @@ namespace DnsServerCore { case TopStatsType.TopClients: { - IDictionary clientIpMap = await ResolvePtrTopClientsAsync(topStatsData); + bool noReverseLookup = request.GetQueryOrForm("noReverseLookup", bool.Parse, false); + bool onlyRateLimitedClients = request.GetQueryOrForm("onlyRateLimitedClients", bool.Parse, false); + + IDictionary clientIpMap = null; + + if (!noReverseLookup) + clientIpMap = await ResolvePtrTopClientsAsync(topStatsData); jsonWriter.WritePropertyName("topClients"); jsonWriter.WriteStartArray(); foreach (KeyValuePair item in topStatsData) { + bool rateLimited = _dnsWebService.DnsServer.IsQpmLimitCrossed(IPAddress.Parse(item.Key)); + + if (onlyRateLimitedClients && !rateLimited) + continue; + jsonWriter.WriteStartObject(); jsonWriter.WriteString("name", item.Key); - if (clientIpMap.TryGetValue(item.Key, out string clientDomain) && !string.IsNullOrEmpty(clientDomain)) + if ((clientIpMap is not null) && clientIpMap.TryGetValue(item.Key, out string clientDomain) && !string.IsNullOrEmpty(clientDomain)) jsonWriter.WriteString("domain", clientDomain); jsonWriter.WriteNumber("hits", item.Value); - jsonWriter.WriteBoolean("rateLimited", _dnsWebService.DnsServer.IsQpmLimitCrossed(IPAddress.Parse(item.Key))); + jsonWriter.WriteBoolean("rateLimited", rateLimited); jsonWriter.WriteEndObject(); }