Last active
April 29, 2025 14:33
-
-
Save provegard/9294617 to your computer and use it in GitHub Desktop.
Python script for dumping wallet addresses and private keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# --------------------------------------------------------------------------- | |
# This software is in the public domain, furnished "as is", without technical | |
# support, and with no warranty, express or implied, as to its usefulness for | |
# any purpose. | |
# | |
# Usage: | |
# ./dump_wallet_addresses.py <wallet binary> | |
# | |
# Simple Python program that communicates with your <whatever>coin wallet | |
# (assuming it's bitcoin wallet compatible) in order to list all addresses | |
# together with their private keys. Both normally visible and hidden/secret | |
# addresses are listed. | |
# | |
# There is no error handling. Make sure the wallet binary is in the search | |
# path, or pass its full path. | |
# | |
# Author: Per Rovegård | |
# --------------------------------------------------------------------------- | |
import sys | |
import subprocess | |
import json | |
walletBin = "" | |
def execWalletCommand(cmd, expectsJson): | |
p = subprocess.Popen([walletBin] + cmd, stdout=subprocess.PIPE) | |
out, err = p.communicate() | |
if expectsJson: | |
return json.loads(out) | |
return out | |
def addAddressesFromGroupings(target): | |
result = execWalletCommand(["listaddressgroupings"], True) | |
for grouping in result: | |
for group in grouping: | |
addr = group[0] | |
if addr not in target: | |
target[addr] = {} | |
target[addr]["balance"] = group[1] | |
if len(group) > 2: | |
target[addr]["account"] = group[2] | |
def addAddressesFromAccounts(target): | |
accounts = execWalletCommand(["listaccounts"], True) | |
for key in accounts: | |
addresses = execWalletCommand(["getaddressesbyaccount", key], True) | |
for addr in addresses: | |
if addr not in target: | |
target[addr] = {} | |
target[addr]["account"] = key | |
def getPrivKeyForAddress(address): | |
return execWalletCommand(["dumpprivkey", address], False).strip() | |
def main(): | |
global walletBin | |
if len(sys.argv) < 2: | |
print "Usage: %s <wallet binary>" % (sys.argv[0], ) | |
sys.exit(1) | |
walletBin = sys.argv[1] | |
target = {} | |
addAddressesFromAccounts(target) | |
addAddressesFromGroupings(target) | |
for addr in target: | |
obj = target[addr] | |
balance = obj["balance"] if "balance" in obj else 0 | |
account = obj["account"] if "account" in obj else "<unknown>" | |
if account == "": | |
account = '""' | |
print "%s\t%s\t%.8f\t%s" % (addr, getPrivKeyForAddress(addr), balance, account) | |
if __name__ == "__main__": | |
main() |
Bitcoin address දුන්නහම ඒකෙ ප්රයිවට් keyගන්න පුළුවන් වෙන්න
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! The usage is in the script:
You can pass in the full path to your Bitcoin-compatible wallet binary.