|
3 | 3 | Simple script to check the status of all Bitcoin Core DNS seeds.
|
4 | 4 | Seeds are available from https://github.com/bitcoin/bitcoin/blob/master/src/kernel/chainparams.cpp
|
5 | 5 | '''
|
| 6 | +import argparse |
6 | 7 | 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 | + |
7 | 18 |
|
8 | 19 | SEEDS_PER_NETWORK={
|
9 | 20 | 'mainnet': [
|
@@ -43,11 +54,69 @@ def check_seed(x):
|
43 | 54 | else:
|
44 | 55 | print(f"\x1b[91mFAIL\x1b[0m {x}")
|
45 | 56 |
|
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 | + |
47 | 93 | for (network, seeds) in SEEDS_PER_NETWORK.items():
|
48 | 94 | print(f"\x1b[90m* \x1b[97m{network}\x1b[0m")
|
49 | 95 |
|
50 | 96 | for hostname in seeds:
|
51 | 97 | check_seed(hostname)
|
52 | 98 |
|
53 | 99 | 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