Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # get bitcoinutils from
- # https://github.com/karask/python-bitcoin-utils
- import requests, json, time, re
- from random import randint
- from threading import Thread, Lock
- from multiprocessing import Pool, TimeoutError, Process, Queue, Value
- from bitcoinutils.keys import P2pkhAddress, PrivateKey, PublicKey
- from bitcoinutils.setup import setup
- CHECKCOMPR = True # check compressed addresses
- MAKERS = 4
- BTCTHREADS = 1
- BLOCKCHAINTHREADS = 1
- ADDRESSTHREADS = 3
- QUEUESIZE = 2000
- NUMBLOCKCHAIN = 120 # how many addresses to check
- NUMBTC = 400
- MAXPAGE=452312848583266388373324160190187140050146735465136345244551418521555318338
- class Generator(Process):
- def __init__(self, queue):
- Process.__init__(self)
- self.queue = queue
- print("Key generator started")
- def run(self):
- while True:
- # if self.queue.qsize() < QUEUESIZE:
- self.generate()
- def generate(self):
- pk = PrivateKey()
- pubk = pk.get_public_key()
- # uncompressed wif & address
- wif = pk.to_wif(compressed=False)
- address = pubk.get_address(compressed=False).to_address()
- self.queue.put([wif, address])
- # print(address, wif)
- # compressed wif & address
- if CHECKCOMPR:
- cwif = pk.to_wif(compressed=True)
- caddress = pubk.get_address(compressed=True).to_address()
- self.queue.put([cwif, caddress])
- # print(caddress, cwif)
- class Downloader(Thread):
- def __init__(self, queue, num, downtype):
- Thread.__init__(self)
- self.queue = queue
- self.num = num
- self.downtype = downtype
- self.tstart = time.time()
- if self.downtype == "BTC":
- self.min_num = NUMBTC
- print("BTC.com downloader started")
- else:
- self.min_num = NUMBLOCKCHAIN
- print("Blockhain.info downloader started")
- def run(self):
- while True:
- if self.queue.qsize() >= self.min_num:
- part = []
- for i in range(self.min_num):
- part.append(self.queue.get())
- self.check(part)
- # print(part)
- else:
- time.sleep(2)
- def check(self, part):
- if self.downtype == "BTC":
- check_btccom(part)
- else:
- check_blockchaininfo(part)
- self.on_download_finished(self.min_num)
- def on_download_finished(self, downloaded):
- with self.num.get_lock():
- self.num.value += downloaded
- qlen = self.queue.qsize()
- t = time.time()
- print("checked:", self.num.value, "avg speed:", self.num.value / (t-self.tstart), "wal/s, queue:", qlen)
- class AddressDownloader(Thread):
- def __init__(self, queue):
- Thread.__init__(self)
- print("Addresskeys downloader started")
- self.queue = queue
- def run(self):
- while True:
- wallets = get_address_keys(get_random_page())
- for w in wallets:
- self.queue.put(w)
- time.sleep(1 + randint(0,1))
- def generate_wallets(num):
- # generate
- wallets = []
- if CHECKCOMPR:
- r = int(num/2)
- else:
- r = num
- for i in range(r):
- pk = PrivateKey()
- pubk = pk.get_public_key()
- # uncompressed wif & address
- wif = pk.to_wif(compressed=False)
- address = pubk.get_address(compressed=False).to_address()
- wallets.append([wif, address])
- # compressed wif & address
- if CHECKCOMPR:
- cwif = pk.to_wif(compressed=True)
- caddress = pubk.get_address(compressed=True).to_address()
- wallets.append([cwif, caddress])
- # test:
- # wallets.append(["hui","15EW3AMRm2yP6LEF5YKKLYwvphy3DmMqN6"])
- return wallets
- def check_btccom(wallets):
- # https://btc.com/api-doc#General
- # https://chain.api.btc.com/v3/address/15urYnyeJe3gwbGJ74wcX89Tz7ZtsFDVew,1PErRgFdo757pyyMxFiwB326vuymXC3hev
- # test:
- # wallets.append(["wif", "1PErRgFdo757pyyMxFiwB326vuymXC3hev"])
- dic = {}
- url = "https://chain.api.btc.com/v3/address/"
- for wallet in wallets:
- url += wallet[1] + ","
- dic[wallet[1]] = wallet[0]
- url = url[:len(url)-1]
- # print(url)
- while True:
- try:
- res = requests.get(url)
- try:
- js = json.loads(res.text)
- # print(js)
- err = js["err_no"]
- data = js["data"]
- for info in data:
- if info == None and err == 0:
- continue
- # these will be missing in logs
- # address = info["address"]
- # wif = dic[address]
- # balance = info["balance"]
- # txs = info["tx_count"]
- else:
- address = info["address"]
- wif = dic[address]
- balance = info["balance"]
- txs = info["tx_count"]
- evaluate_wallet(address, wif, balance, txs)
- return
- except ValueError as e:
- print("Error: " + str(e))
- # print(url)
- time.sleep(1)
- pass # invalid json
- else:
- pass # valid json
- except requests.exceptions.RequestException as e:
- print("Error: " + str(e))
- # print(url)
- time.sleep(1)
- else:
- pass
- def check_blockchaininfo(wallets):
- # example: https://blockchain.info/balance?active=1MDUoxL1bGvMxhuoDYx6i11ePytECAk9QK|15EW3AMRm2yP6LEF5YKKLYwvphy3DmMqN6
- url = "https://blockchain.info/balance?active="
- for wallet in wallets:
- url += "|" + wallet[1]
- # print(url)
- while True:
- try:
- res = requests.get(url)
- try:
- js = json.loads(res.text)
- # print(js)
- for wallet in wallets:
- info = js.get(wallet[1])
- balance = info["final_balance"]
- txs = info["n_tx"]
- evaluate_wallet(wallet[1], wallet[0], balance, txs)
- return
- except ValueError as e:
- print("Error: " + str(e))
- pass # invalid json
- # print(url)
- time.sleep(1)
- else:
- pass # valid json
- except requests.exceptions.RequestException as e:
- print("Error: " + str(e))
- # print(url)
- time.sleep(1)
- # pass
- else:
- pass
- def evaluate_wallet(address, wif, balance, txs):
- # print("Balance:", balance, "\tTxs:", txs, "\tAddress:", address, "\tWIF:", wif)
- # write_wallet("log", address, wif, balance, txs) # UNCOMMENTING THIS WILL WRITE EVERY WALLET TO LOG FILE
- if balance > 0 or txs > 0:
- print("Found! Balance:", balance, "\tTxs:", txs, "\tAddress:", address, "\tWIF:", wif)
- write_wallet("pyfound.txt", address, wif, balance, txs)
- def write_wallet(filename, address, wif, balance, txs):
- f = open(filename, "a")
- f.write(str(balance) + "\t" + str(txs) + "\t" + address +"\t"+ wif+ "\n")
- f.close()
- def get_address_keys(page):
- # 256 keys per page
- url = "https://addresskeys.com/btcpage?&pagenum=" + str(page)
- try:
- res = requests.get(url)
- m = re.search('(const keys = )(.*)', res.text)
- # if m.groups > 0:
- try:
- # print(m.group(2))
- wallets0 = json.loads(m.group(2).replace("},]", "}]"))
- wallets = []
- for w in wallets0:
- wallets.append([w["wif"], w["pub"]])
- wallets.append([w["wif"], w["cpub"]])
- return wallets
- except ValueError as e:
- print("Error: " + str(e))
- # print(url)
- time.sleep(1)
- pass # invalid json
- else:
- pass # valid json
- except requests.exceptions.RequestException as e:
- print("Error: " + str(e))
- # print(url)
- time.sleep(1)
- else:
- pass
- def get_random_page():
- return randint(1, MAXPAGE)
- def find_page(wif, page=MAXPAGE//2, lastpage=1):
- t0 = time.time()
- while True:
- if page != lastpage:
- dist = abs(page - lastpage)
- lastpage = page
- print("Current page:", page, "time elapsed:", time.time()-t0)
- wallets = get_address_keys(page)
- check_btccom(wallets) # gotta check them all
- moveleft = True
- for w in wallets:
- if w[0] < wif:
- moveleft = False
- elif w[0] == wif:
- print("FOUND! Page: ", page)
- return page
- if moveleft:
- page -= dist//2 + 1
- else:
- page += dist//2 + 1
- time.sleep(3)
- if __name__ == "__main__":
- print("Ya prosnulsya!")
- setup("mainnet")
- num = Value('i', 0)
- q = Queue()
- for x in range(MAKERS):
- p = Generator(q)
- p.start()
- for x in range(BLOCKCHAINTHREADS):
- t = Downloader(q, num, "Blockchain")
- t.start()
- for x in range(BTCTHREADS):
- t = Downloader(q, num, "BTC")
- t.start()
- for x in range(ADDRESSTHREADS):
- t = AddressDownloader(q)
- t.start()
- while True:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement