【发布时间】:2019-10-15 23:46:36
【问题描述】:
我正在制作一个新脚本,它将作为以太坊私钥的输入列表并生成带有余额的相应地址,如果发现余额以及私钥和地址,则将余额保存在文件中。
现在,我几乎可以肯定我的问题出在条件范围内,但无法弄清楚。
脚本步骤: 1. 将私钥文件作为输入(-i 标志) 2.将它们转换为公共地址/解码它们 3. 触发对 Etherscan 的 API 调用以获取有关地址的信息 4.如果API调用中json()["result"] > 0,则将其写入输出文件(-o标志),否则打印输出并休眠1秒
谁能指出我在哪里犯了错误?
我的代码:
#!/usr/bin/python
import sys, os, argparse, requests, ethereum, binascii, time
from multiprocessing import Pool
def scanether(balance):
try:
# Convert private key to address and print the result
eth_address = ethereum.utils.privtoaddr(INPUTFILE)
eth_address_hex = binascii.hexlify(eth_address).decode("utf-8")
eth_balance = requests.get("https://api.etherscan.io/api?module=account&action=balance&address=0x" + eth_address_hex + "&tag=latest&apikey=APIKEYHERE").json()["result"]
# Check if the result is > 0
if ('result' != 0) in r.eth_balance:
print("[*] Address with balance found: " + eth_address_hex + priv)
# Write match to OUTPUTFILE
fHandle = open(OUTPUTFILE,'a')
fHandle.write(eth_address_hex + privkey + "\n")
fHandle.close()
else:
print("balance: {} address: 0x{} privkey: {}".format(float(eth_balance)/100000000, eth_address_hex, priv))
time.sleep(1)
except Exception as e:
return
if __name__ == '__main__':
print("""
# Finding the Ethereum address with balance
""")
# Parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--inputfile', default='input.txt', help='input file')
parser.add_argument('-o', '--outputfile', default='output.txt', help='output file')
parser.add_argument('-t', '--threads', default=200, help='threads')
args = parser.parse_args()
INPUTFILE=args.inputfile
OUTPUTFILE=args.outputfile
MAXPROCESSES=int(args.threads)
try:
addresses = open(INPUTFILE, "r").readlines()
except FileNotFoundError as e:
print(e)
exit(e.errno)
print("Scan in progress...")
pool = Pool(processes=MAXPROCESSES)
pool.map(scanether, addresses)
print("Scan finished.")
【问题讨论】:
-
HTTP 状态码是否 == 200?是否引发异常?
-
尝试在 except: 中打印一些内容并检查。获取结果时可能有异常。
-
@IvanVinogradov 请求的状态码是 200,没有引发异常
标签: python if-statement python-requests blockchain ethereum