Skip to content

Commit 65bcdc5

Browse files
committed
dns: add dns seed provider filtering based on supported flags
1 parent 0cb8c9b commit 65bcdc5

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

check-dnsseeds.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@
33
Simple script to check the status of all Bitcoin Core DNS seeds.
44
Seeds are available from https://github.com/bitcoin/bitcoin/blob/master/src/kernel/chainparams.cpp
55
'''
6+
import argparse
67
import subprocess
8+
from itertools import combinations
9+
10+
NODE_NONE = 0
11+
NODE_NETWORK = (1 << 0)
12+
NODE_BLOOM = (1 << 2)
13+
NODE_WITNESS = (1 << 3)
14+
NODE_COMPACT_FILTERS = (1 << 6)
15+
NODE_NETWORK_LIMITED = (1 << 10)
16+
NODE_P2P_V2 = (1 << 11)
17+
718

819
SEEDS_PER_NETWORK={
920
'mainnet': [
@@ -43,11 +54,69 @@ def check_seed(x):
4354
else:
4455
print(f"\x1b[91mFAIL\x1b[0m {x}")
4556

46-
if __name__ == '__main__':
57+
def get_combinations(services):
58+
59+
all_flags = services.values()
60+
all_combinations = []
61+
62+
for i in range(1, len(all_flags) + 1):
63+
for combo in combinations(all_flags, i):
64+
combination_value = sum(combo)
65+
combination_hex = hex(combination_value)[2:].upper()
66+
combination_names = [service for service, flag in services.items() if flag in combo]
67+
all_combinations.append((combination_hex, combination_names))
68+
69+
return all_combinations
70+
71+
def check_dns_support(combination_hex, provider):
72+
"""
73+
Checks if a DNS provider supports a given combination of service flags.
74+
"""
75+
76+
domain = f"x{combination_hex}.{provider}"
77+
command = ["dig", domain]
78+
try:
79+
result = subprocess.run(command, capture_output=True, check=True)
80+
output = result.stdout.decode("utf-8")
81+
return "ANSWER SECTION" in output
82+
except subprocess.CalledProcessError:
83+
return False
84+
85+
if __name__ == "__main__":
86+
parser = argparse.ArgumentParser(description='Bitcoin Core Filter DNS Seeds')
87+
parser.add_argument('--filter-services', action='store_true', help='Scan which filters are in use')
88+
args = parser.parse_args()
89+
90+
91+
print("\nBitcoin Core DNS Seed Status Check:\n")
92+
4793
for (network, seeds) in SEEDS_PER_NETWORK.items():
4894
print(f"\x1b[90m* \x1b[97m{network}\x1b[0m")
4995

5096
for hostname in seeds:
5197
check_seed(hostname)
5298

5399
print()
100+
101+
print("\n")
102+
103+
if args.filter_services:
104+
combinations = get_combinations({
105+
"NODE_NONE": NODE_NONE,
106+
"NODE_NETWORK": NODE_NETWORK,
107+
"NODE_BLOOM": NODE_BLOOM,
108+
"NODE_WITNESS": NODE_WITNESS,
109+
"NODE_COMPACT_FILTERS": NODE_COMPACT_FILTERS,
110+
"NODE_NETWORK_LIMITED": NODE_NETWORK_LIMITED,
111+
"NODE_P2P_V2": NODE_P2P_V2,
112+
})
113+
114+
print("All possible combinations of node services and their bit flags in hexadecimal:")
115+
for combination_hex, service_names in combinations:
116+
print(f" Bit flag (hex): {combination_hex} - Service: {', '.join(service_names)}")
117+
118+
for (network, seeds) in SEEDS_PER_NETWORK.items():
119+
for hostname in seeds:
120+
supports_combination = check_dns_support(combination_hex, hostname)
121+
print(f" Network: {network}, Provider: {hostname} - Supports Service: {supports_combination}")
122+

0 commit comments

Comments
 (0)