Skip to content

Commit 8e598e9

Browse files
committed
dns: check dns seeds supporting service flags combinations
1 parent 84e37d2 commit 8e598e9

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

check-dnsseeds.py

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,26 @@ def check_seed(x):
5959
else:
6060
print(f"\x1b[91mFAIL\x1b[0m {x}")
6161

62-
def has_answer_section(domain):
62+
def get_combinations(services):
63+
64+
all_flags = services.values()
65+
all_combinations = []
66+
67+
for i in range(1, len(all_flags) + 1):
68+
for combo in combinations(all_flags, i):
69+
combination_value = sum(combo)
70+
combination_hex = hex(combination_value)[2:].upper()
71+
combination_names = [service for service, flag in services.items() if flag in combo]
72+
all_combinations.append((combination_hex, combination_names))
73+
74+
return all_combinations
75+
76+
def check_dns_support(combination_hex, provider):
6377
"""
64-
Executes a dig command for the given domain and checks for an answer section.
78+
Checks if a DNS provider supports a given combination of flags.
6579
"""
80+
81+
domain = f"x{combination_hex}.{provider}"
6682
command = ["dig", domain]
6783
try:
6884
result = subprocess.run(command, capture_output=True, check=True)
@@ -71,14 +87,6 @@ def has_answer_section(domain):
7187
except subprocess.CalledProcessError:
7288
return False
7389

74-
def get_hex_from_combination(*flags):
75-
"""
76-
Calculates the hexadecimal representation of the combination value.
77-
"""
78-
combination_value = sum(flags)
79-
hex_value = hex(combination_value)[2:].upper()
80-
return f"x{hex_value}"
81-
8290
if __name__ == "__main__":
8391
print("\nBitcoin Core DNS Seed Status Check:\n")
8492

@@ -91,23 +99,22 @@ def get_hex_from_combination(*flags):
9199
print()
92100

93101
print("\n")
94-
95-
all_flags = [NODE_NONE, NODE_NETWORK, NODE_BLOOM, NODE_WITNESS, NODE_COMPACT_FILTERS, NODE_NETWORK_LIMITED, NODE_P2P_V2]
96-
all_combinations = []
97-
98-
for i in range(1, len(all_flags) + 1):
99-
for combo in combinations(all_flags, i):
100-
combination = sum(combo)
101-
hex_value = get_hex_from_combination(*combo)
102-
all_combinations.append((combo, hex_value))
103-
104-
print("All possible combinations and their hexadecimal values:")
105-
for combination, hex_value in all_combinations:
106-
combination_names = [flag_name for flag_name, flag_value in zip(["NODE_NONE", "NODE_NETWORK", "NODE_BLOOM", "NODE_WITNESS", "NODE_COMPACT_FILTERS", "NODE_NETWORK_LIMITED", "NODE_P2P_V2"], combination) if flag_value != 0]
107-
combination_string = ", ".join(combination_names)
108-
print(f"Combination: {combination_string} => Hexadecimal Value: {hex_value}")
102+
combinations = get_combinations({
103+
"NODE_NONE": NODE_NONE,
104+
"NODE_NETWORK": NODE_NETWORK,
105+
"NODE_BLOOM": NODE_BLOOM,
106+
"NODE_WITNESS": NODE_WITNESS,
107+
"NODE_COMPACT_FILTERS": NODE_COMPACT_FILTERS,
108+
"NODE_NETWORK_LIMITED": NODE_NETWORK_LIMITED,
109+
"NODE_P2P_V2": NODE_P2P_V2,
110+
})
111+
112+
print("All possible combinations of node services and their bit flags in hexadecimal:")
113+
for combination_hex, service_names in combinations:
114+
print(f" Bit flag (hex): {combination_hex} - Service: {', '.join(service_names)}")
109115

110116
for provider in DNS_SEED_PROVIDERS:
111-
domain = f"{hex_value}.{provider}"
112-
has_answer = has_answer_section(domain)
113-
print(f" {domain}: {has_answer}")
117+
supports_combination = check_dns_support(combination_hex, provider)
118+
print(f" Provider: {provider} - Supports Service: {supports_combination}")
119+
120+

0 commit comments

Comments
 (0)