catch (Pyhon script):
import sys
import base58
from bitcoinrpc.authproxy import AuthServiceProxy
RPC_ADDRESS="you-ip:8332"
RPC_USER="you-username"
RPC_PASSWORD="you passwd"
def connect(address, user, password):
return AuthServiceProxy("http://%s:%s@%s"%(user, password, address))
def extract_block_addresses(rpc, block_hash):
block = rpc.getblock(block_hash)
addresses = []
for tx in block[u'tx']:
raw_tx = rpc.getrawtransaction(tx, True)
if not raw_tx.has_key('vout'):
sys.stderr.write("Transaction %s has no 'vout': %s\n"%(tx, raw_tx))
break
for vout in raw_tx[u'vout']:
if not vout.has_key("scriptPubKey"):
sys.stderr.write("Vout %s of Transaction %s has no 'scriptPubKey'\n"%(vout, tx))
break
if vout["scriptPubKey"]["type"] == "nulldata":
# arbitrary data
break
elif vout['scriptPubKey'].has_key('addresses'):
addresses.extend(vout['scriptPubKey']['addresses'])
else:
sys.stderr.write("Can't handle %s transaction output type in transaction %s\n"%(vout["scriptPubKey"]["type"], raw_tx))
return addresses
if __name__ == "__main__":
if len(sys.argv) > 1:
start_block = int(sys.argv[1])
else:
start_block = 1
if len(sys.argv) > 2:
end_block = int(sys.argv[2])
else:
end_block = 0
rpc = connect(RPC_ADDRESS, RPC_USER, RPC_PASSWORD)
if end_block == 0:
end_block = rpc.getblockcount()
b = start_block
for b in xrange(start_block, end_block+1):
print(b)
try:
block_hash = rpc.getblockhash(b)
for addr in extract_block_addresses(rpc, block_hash):
print(addr + "," + base58.b58decode_check(str(addr)).encode('hex')[2:])
except:
rpc = connect(RPC_ADDRESS, RPC_USER, RPC_PASSWORD)
block_hash = rpc.getblockhash(b)
for addr in extract_block_addresses(rpc, block_hash):
print(addr + "," + base58.b58decode_check(str(addr)).encode('hex')[2:])
You need installed and full synced Bitcoin core wallet.
Config for botcoin core (bitcoin.conf):
server=1
txindex=1
rpcthreads=32
rpcuser=
rpcpassword=
rpcbind=0.0.0.0
rpcallowip=