首先立项之前先确定脚本工具的功能内容:
总体来说就是用Python代码实现一个用于生成随机BTC私钥和地址的脚本,并且输出相关信息“包括压缩和非压缩形式的地址、对应的WIF(Wallet Import Format)私钥、以及通过这些私钥生成的地址的余额”。
核心代码:
from bitcash import *
from bitcash.format import bytes_to_wif
import random
import atexit
import time
from colorama import Fore, Style
art = """
_ _ ___ _ _ ______ _____ _ _ ____ ____ _ _ _ ____
| | | |/ _ \| \ | |/ ___\ \ / |_ _| \ | |/ ___|/ ___| | | | | | __ )
| |_| | | | | \| | | _ \ V / | || \| | | _| | | | | | | | _ \
| _ | |_| | |\ | |_| | | | | || |\ | |_| | |___| |__| |_| | |_) |
|_| |_|\___/|_| \_|\____| |_| |___|_| \_|\____|\____|_____\___/|____/
||---------------------------------------------------------------------||
||- WebSite --------------------------------httpS://bbs.hongying.club -||
||- Telegram-------------------------https://t.me/hongyingclub_office -||
||- DEV ------------------------------------- DEV.to/HongYingclub -||
||=====================================================================||
"""
print("Start ...")
print(art)
count = 0
total = 0
while True:
x = 1
y = 115792089237316195423570985008687907852837564279074904382605163141518161494336
ran = random.randint(x, y)
seed = str(ran)
key = Key.from_int(ran)
wif = bytes_to_wif(key.to_bytes(), compressed=False)
wif2 = bytes_to_wif(key.to_bytes(), compressed=True)
key1 = Key(wif)
privkey = key.to_hex()
privkey2 = key1.to_hex()
caddr = key.address # For Compressed Address
uaddr = key1.address # For UNCompressed Address
bal = key.get_balance('bch')
bal2 = key1.get_balance('bch')
count += 1
total += 2
#=============================================
print("=============================================")
print(Fore.YELLOW+"\nCurrent PrivateKey --> "+seed)
print(Fore.GREEN+"Compressed Address : "+Fore.LIGHTGREEN_EX+caddr+Style.RESET_ALL)
print("Private Key : "+privkey)
print(Fore.RED+"WIF : "+wif2+Fore.CYAN+" |BAL : "+Style.RESET_ALL+bal)
print("-----------------------------")
print(Fore.GREEN+"Uncompressed Address : "+Fore.LIGHTGREEN_EX+uaddr+Style.RESET_ALL)
print("Private Key : "+privkey2)
print(Fore.RED+"WiF : "+wif+Fore.CYAN+" |BAL : "+Style.RESET_ALL+bal2)
print(Fore.YELLOW+"Scan Number : "+Fore.WHITE+str(count)+Fore.MAGENTA+" Total Wallet : "+Fore.WHITE+str(total))
time.sleep(1)
代码分析:
from bitcash import *
from bitcash.format import bytes_to_wif
import random
import atexit
import time
这段代码使用了 bitcash 库,这是一个用于比特币现金(BCH)操作的Python库。
ran = random.randint(x, y)
seed = str(ran)
key = Key.from_int(ran)
wif = bytes_to_wif(key.to_bytes(), compressed=False)
wif2 = bytes_to_wif(key.to_bytes(), compressed=True)
key1 = Key(wif)
privkey = key.to_hex()
privkey2 = key1.to_hex()
代码中定义了一个无限循环,每次循环都会生成一个新的随机私钥,然后计算出对应的WIF格式的私钥、压缩和非压缩的比特币地址,并查询这些地址的余额。
注意:这个脚本生成的私钥对应的地址可能没有任何余额,因为它们是随机生成的,并不对应任何实际的比特币交易。
有空可以关注或者加入我们BBS大家研究研究