Github Mirror / telegraf-plugins: 431e09f3




Detect port ranges and walk them to increment counters correctly

Detect port ranges and walk them to increment counters correctly

Commit 431e09f3.

Authored 2022-05-14T12:38:33.000+01:00 by B Tasker in project Github Mirror / telegraf-plugins

+16 lines -5 lines

Commit Signature

Changes

diff --git a/tor-daemon/tor-daemon.py b/tor-daemon/tor-daemon.py
--- a/tor-daemon/tor-daemon.py
+++ b/tor-daemon/tor-daemon.py
# @@ -166,7 +166,8 @@ def process_exit_policy(policy_line):
# "unique_hosts" : 0,
# "unique_ports" : 0,
# "wildcard_port" : 0,
# - "specific_port" : 0
# + "specific_port" : 0,
# + "port_range": 0,
# }
#
# hosts = []
# @@ -190,12 +191,22 @@ def process_exit_policy(policy_line):
# hosts.append(ip)
#
# port = parts[1].split(":")[-1]
# - ports.append(port)
#
# - if port == "*":
# - counters['wildcard_port'] += 1
# + if "-" in port:
# + # It's a range
# + counters["port_range"] += 1
# + port_parts = [ int(x) for x in port.split("-") ]
# + while port[0] <= port[1]:
# + ports.append(port[0])
# + counters['specific_port'] += 1
# + port[0] += 1
# +
# else:
# - counters['specific_port'] += 1
# + ports.append(port)
# + if port == "*":
# + counters['wildcard_port'] += 1
# + else:
# + counters['specific_port'] += 1
#
# # Calculate the unique counts
# counters["unique_hosts"] = len(set(hosts))
#