Skip to content

Instantly share code, notes, and snippets.

@coderfi
Created November 16, 2018 00:11
Show Gist options
  • Save coderfi/ff1961ba510ac9af790146d2ab43ca7c to your computer and use it in GitHub Desktop.
Save coderfi/ff1961ba510ac9af790146d2ab43ca7c to your computer and use it in GitHub Desktop.
A python script to resolve a few registered bitcoin nodes from the DNS entries of some seed nodes.
#!/usr/bin/env python3
from datetime import datetime
import dns.resolver
import time
# pip install --user dnspython
# https://bitcoin.stackexchange.com/questions/14371/what-is-a-dns-seed-node-vs-a-seed-node
# https://bitcoin.stackexchange.com/questions/2027/how-does-the-bitcoin-client-make-the-initial-connection-to-the-bitcoin-network/2030#2030
loops = 5
seeds = [
"seed.bitcoin.sipa.be",
"dnsseed.bluematt.me",
"dnsseed.bitcoin.dashjr.org",
"seed.bitcoinstats.com",
"seed.bitcoin.jonasschnelli.ch",
"seed.btc.petertodd.org",
"seed.bitcoin.sprovoost.nl",
"bitseed.xf2.org"
]
print(" # updated %s %s" % (datetime.now().strftime("%c"), __file__))
resolver = dns.resolver.Resolver()
hosts = set()
for seed in seeds:
print(" # seed: " + seed)
for _ in range(loops):
answers = resolver.query(seed, "A") # Lookup the 'A' record(s)
hosts.update([a.address for a in answers])
time.sleep(0.1)
for host in sorted(hosts):
print(" - " + host)
print()
s = ""
for h in sorted(hosts):
s += '"-connect=%s", ' % h
print(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment