Advertisement
Guest User

lucky-yoba-multi.py

a guest
Nov 26th, 2018
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.79 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. # get bitcoinutils from
  4. # https://github.com/karask/python-bitcoin-utils
  5.  
  6. import requests, json, time, re
  7. from random import randint
  8. from threading import Thread, Lock
  9. from multiprocessing import Pool, TimeoutError, Process, Queue, Value
  10. from bitcoinutils.keys import P2pkhAddress, PrivateKey, PublicKey
  11. from bitcoinutils.setup import setup
  12.  
  13. CHECKCOMPR = True # check compressed addresses
  14.  
  15. MAKERS = 4
  16. BTCTHREADS = 1
  17. BLOCKCHAINTHREADS = 1
  18. ADDRESSTHREADS = 3
  19. QUEUESIZE = 2000
  20.  
  21. NUMBLOCKCHAIN = 120 # how many addresses to check
  22. NUMBTC = 400
  23.  
  24. MAXPAGE=452312848583266388373324160190187140050146735465136345244551418521555318338
  25.  
  26. class Generator(Process):
  27.     def __init__(self, queue):
  28.         Process.__init__(self)
  29.         self.queue = queue
  30.         print("Key generator started")
  31.  
  32.     def run(self):
  33.         while True:
  34.             # if self.queue.qsize() < QUEUESIZE:
  35.             self.generate()
  36.  
  37.     def generate(self):
  38.         pk = PrivateKey()
  39.         pubk = pk.get_public_key()
  40.  
  41.         # uncompressed wif & address
  42.         wif = pk.to_wif(compressed=False)
  43.         address = pubk.get_address(compressed=False).to_address()
  44.         self.queue.put([wif, address])
  45.  
  46.         # print(address, wif)
  47.         # compressed wif & address
  48.         if CHECKCOMPR:
  49.             cwif = pk.to_wif(compressed=True)
  50.             caddress = pubk.get_address(compressed=True).to_address()
  51.             self.queue.put([cwif, caddress])
  52.             # print(caddress, cwif)
  53.  
  54. class Downloader(Thread):
  55.     def __init__(self, queue, num, downtype):
  56.         Thread.__init__(self)
  57.         self.queue = queue
  58.         self.num = num
  59.         self.downtype = downtype
  60.         self.tstart = time.time()
  61.         if self.downtype == "BTC":
  62.             self.min_num = NUMBTC
  63.             print("BTC.com downloader started")
  64.         else:
  65.             self.min_num = NUMBLOCKCHAIN
  66.             print("Blockhain.info downloader started")
  67.        
  68.     def run(self):
  69.         while True:
  70.             if self.queue.qsize() >= self.min_num:
  71.                 part = []
  72.                 for i in range(self.min_num):
  73.                     part.append(self.queue.get())
  74.                 self.check(part)
  75.                 # print(part)
  76.             else:
  77.                 time.sleep(2)
  78.  
  79.     def check(self, part):
  80.         if self.downtype == "BTC":
  81.             check_btccom(part)
  82.         else:
  83.             check_blockchaininfo(part)
  84.         self.on_download_finished(self.min_num)
  85.  
  86.     def on_download_finished(self, downloaded):
  87.         with self.num.get_lock():
  88.             self.num.value += downloaded
  89.         qlen = self.queue.qsize()
  90.         t = time.time()
  91.         print("checked:", self.num.value, "avg speed:", self.num.value / (t-self.tstart), "wal/s, queue:", qlen)
  92.  
  93. class AddressDownloader(Thread):
  94.     def __init__(self, queue):
  95.         Thread.__init__(self)
  96.         print("Addresskeys downloader started")
  97.         self.queue = queue
  98.        
  99.     def run(self):
  100.         while True:
  101.             wallets = get_address_keys(get_random_page())
  102.             for w in wallets:
  103.                 self.queue.put(w)
  104.             time.sleep(1 + randint(0,1))
  105.  
  106. def generate_wallets(num):
  107.     # generate
  108.     wallets = []
  109.  
  110.     if CHECKCOMPR:
  111.         r = int(num/2)
  112.     else:
  113.         r = num
  114.  
  115.     for i in range(r):
  116.         pk = PrivateKey()
  117.         pubk = pk.get_public_key()
  118.  
  119.         # uncompressed wif & address
  120.         wif = pk.to_wif(compressed=False)
  121.         address = pubk.get_address(compressed=False).to_address()
  122.         wallets.append([wif, address])
  123.  
  124.         # compressed wif & address
  125.         if CHECKCOMPR:
  126.             cwif = pk.to_wif(compressed=True)
  127.             caddress = pubk.get_address(compressed=True).to_address()
  128.             wallets.append([cwif, caddress])
  129.  
  130.     # test:
  131.     # wallets.append(["hui","15EW3AMRm2yP6LEF5YKKLYwvphy3DmMqN6"])
  132.     return wallets
  133.  
  134. def check_btccom(wallets):
  135.     # https://btc.com/api-doc#General
  136.     # https://chain.api.btc.com/v3/address/15urYnyeJe3gwbGJ74wcX89Tz7ZtsFDVew,1PErRgFdo757pyyMxFiwB326vuymXC3hev
  137.     # test:
  138.     # wallets.append(["wif", "1PErRgFdo757pyyMxFiwB326vuymXC3hev"])
  139.     dic = {}
  140.     url = "https://chain.api.btc.com/v3/address/"
  141.     for wallet in wallets:
  142.         url += wallet[1] + ","
  143.         dic[wallet[1]] = wallet[0]
  144.     url = url[:len(url)-1]
  145.     # print(url)
  146.  
  147.     while True:
  148.         try:
  149.             res = requests.get(url)
  150.             try:
  151.                 js = json.loads(res.text)
  152.                 # print(js)
  153.                 err = js["err_no"]
  154.                 data = js["data"]
  155.                 for info in data:
  156.                     if info == None and err == 0:
  157.                         continue
  158.                         # these will be missing in logs
  159.                         # address = info["address"]
  160.                         # wif = dic[address]
  161.                         # balance = info["balance"]
  162.                         # txs = info["tx_count"]
  163.                     else:
  164.                         address = info["address"]
  165.                         wif = dic[address]
  166.                         balance = info["balance"]
  167.                         txs = info["tx_count"]
  168.                         evaluate_wallet(address, wif, balance, txs)
  169.                 return
  170.             except ValueError as e:
  171.                 print("Error: " + str(e))
  172.                 # print(url)
  173.                 time.sleep(1)
  174.                 pass # invalid json
  175.             else:
  176.                 pass # valid json
  177.         except requests.exceptions.RequestException as e:
  178.             print("Error: " + str(e))
  179.             # print(url)
  180.             time.sleep(1)
  181.         else:
  182.             pass
  183.  
  184. def check_blockchaininfo(wallets):
  185.     # example: https://blockchain.info/balance?active=1MDUoxL1bGvMxhuoDYx6i11ePytECAk9QK|15EW3AMRm2yP6LEF5YKKLYwvphy3DmMqN6
  186.     url = "https://blockchain.info/balance?active="
  187.     for wallet in wallets:
  188.         url += "|" + wallet[1]
  189.     # print(url)
  190.  
  191.     while True:
  192.         try:
  193.             res = requests.get(url)
  194.             try:
  195.                 js = json.loads(res.text)
  196.                 # print(js)
  197.                 for wallet in wallets:
  198.                     info = js.get(wallet[1])
  199.                     balance = info["final_balance"]
  200.                     txs = info["n_tx"]
  201.                     evaluate_wallet(wallet[1], wallet[0], balance, txs)
  202.                 return
  203.             except ValueError as e:
  204.                 print("Error: " + str(e))
  205.                 pass # invalid json
  206.                 # print(url)
  207.                 time.sleep(1)
  208.             else:
  209.                 pass # valid json
  210.         except requests.exceptions.RequestException as e:
  211.             print("Error: " + str(e))
  212.             # print(url)
  213.             time.sleep(1)
  214.             # pass
  215.         else:
  216.             pass
  217.  
  218. def evaluate_wallet(address, wif, balance, txs):
  219.     # print("Balance:", balance, "\tTxs:", txs, "\tAddress:", address, "\tWIF:", wif)
  220.     # write_wallet("log", address, wif, balance, txs) # UNCOMMENTING THIS WILL WRITE EVERY WALLET TO LOG FILE
  221.     if balance > 0 or txs > 0:
  222.         print("Found! Balance:", balance, "\tTxs:", txs, "\tAddress:", address, "\tWIF:", wif)
  223.         write_wallet("pyfound.txt", address, wif, balance, txs)
  224.  
  225. def write_wallet(filename, address, wif, balance, txs):
  226.     f = open(filename, "a")
  227.     f.write(str(balance) + "\t" + str(txs) + "\t" + address +"\t"+ wif+ "\n")
  228.     f.close()
  229.  
  230. def get_address_keys(page):
  231.     # 256 keys per page
  232.     url = "https://addresskeys.com/btcpage?&pagenum=" + str(page)
  233.     try:
  234.         res = requests.get(url)
  235.         m = re.search('(const keys = )(.*)', res.text)
  236.         # if m.groups > 0:
  237.         try:
  238.             # print(m.group(2))
  239.             wallets0 = json.loads(m.group(2).replace("},]", "}]"))
  240.             wallets = []
  241.             for w in wallets0:
  242.                 wallets.append([w["wif"], w["pub"]])
  243.                 wallets.append([w["wif"], w["cpub"]])
  244.             return wallets
  245.         except ValueError as e:
  246.             print("Error: " + str(e))
  247.             # print(url)
  248.             time.sleep(1)
  249.             pass # invalid json
  250.         else:
  251.             pass # valid json
  252.     except requests.exceptions.RequestException as e:
  253.         print("Error: " + str(e))
  254.         # print(url)
  255.         time.sleep(1)
  256.     else:
  257.         pass
  258.  
  259. def get_random_page():
  260.     return randint(1, MAXPAGE)
  261.  
  262. def find_page(wif, page=MAXPAGE//2, lastpage=1):
  263.     t0 = time.time()
  264.     while True:
  265.         if page != lastpage:
  266.             dist = abs(page - lastpage)
  267.             lastpage = page
  268.             print("Current page:", page, "time elapsed:", time.time()-t0)
  269.             wallets = get_address_keys(page)
  270.             check_btccom(wallets) # gotta check them all
  271.             moveleft = True
  272.             for w in wallets:
  273.                 if w[0] < wif:
  274.                     moveleft = False
  275.                 elif w[0] == wif:
  276.                     print("FOUND! Page: ", page)
  277.                     return page
  278.             if moveleft:
  279.                 page -= dist//2 + 1
  280.             else:
  281.                 page += dist//2 + 1
  282.             time.sleep(3)
  283.  
  284. if __name__ == "__main__":
  285.     print("Ya prosnulsya!")
  286.     setup("mainnet")
  287.  
  288.     num = Value('i', 0)
  289.     q = Queue()
  290.  
  291.     for x in range(MAKERS):
  292.         p = Generator(q)
  293.         p.start()
  294.  
  295.     for x in range(BLOCKCHAINTHREADS):
  296.         t = Downloader(q, num, "Blockchain")
  297.         t.start()
  298.  
  299.     for x in range(BTCTHREADS):
  300.         t = Downloader(q, num, "BTC")
  301.         t.start()
  302.  
  303.     for x in range(ADDRESSTHREADS):
  304.         t = AddressDownloader(q)
  305.         t.start()
  306.  
  307.     while True:
  308.         pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement