DILSHAD737 commited on
Commit
75d13cc
Β·
verified Β·
1 Parent(s): 20110a9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +251 -0
app.py ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+ import hashlib
4
+ import hmac
5
+ import sys
6
+ import multiprocessing
7
+ from mnemonic import Mnemonic
8
+ import coincurve
9
+ from eth_utils import keccak, to_checksum_address
10
+ from web3 import Web3
11
+
12
+ # ============================================================
13
+ # πŸ› οΈ APNI SETTINGS YAHAN SET KAREIN
14
+ # ============================================================
15
+ CSV_FILE = "14262022_addresses.csv"
16
+
17
+ # βœ… Yahan apni test phrase dalein (jo 25th number par aayegi)
18
+ MY_TEST_PHRASE = "lesson cushion crane affair federal decline limb spend reunion chief cart zebra"
19
+
20
+ NUM_PHRASES = 5000
21
+ SCAN_MODE = "File"
22
+ ACC_START = 0
23
+ ACC_END = 29
24
+ ADDR_START = 0
25
+ ADDR_END = 29
26
+ SHOW_ALL = False
27
+ PASSPHRASE = ""
28
+
29
+ # βœ… Your system has 192 logical cores. 190 workers is the sweet spot.
30
+ NUM_WORKERS = 192
31
+ # ============================================================
32
+
33
+ # Web3 Setup
34
+ alchemy_api_key = "Rjey8KWIGjKik1qfZ4vdU"
35
+ alchemy_url = f"https://eth-mainnet.g.alchemy.com/v2/{alchemy_api_key}"
36
+ web3_eth = Web3(Web3.HTTPProvider(alchemy_url, request_kwargs={"timeout": 10}))
37
+ bsc_url = "https://bsc-dataseed.binance.org/"
38
+ web3_bsc = Web3(Web3.HTTPProvider(bsc_url, request_kwargs={"timeout": 10}))
39
+
40
+ def get_balances(address):
41
+ eth_float, bnb_float = 0.0, 0.0
42
+ eth_str, bnb_str = "0.0", "0.0"
43
+ try:
44
+ eth_wei = web3_eth.eth.get_balance(Web3.to_checksum_address(address))
45
+ eth_float = float(Web3.from_wei(eth_wei, 'ether'))
46
+ if eth_float > 0: eth_str = f"{eth_float:.6f}"
47
+ except Exception: pass
48
+ try:
49
+ bnb_wei = web3_bsc.eth.get_balance(Web3.to_checksum_address(address))
50
+ bnb_float = float(Web3.from_wei(bnb_wei, 'ether'))
51
+ if bnb_float > 0: bnb_str = f"{bnb_float:.6f}"
52
+ except Exception: pass
53
+ return eth_float, bnb_float, eth_str, bnb_str
54
+
55
+ # ============================================================
56
+ # Global Variables for Workers (Shared via Linux Fork)
57
+ # ============================================================
58
+ KNOWN_ADDRESSES = None
59
+ _MNEMONIC = None
60
+
61
+ def init_worker(known_addresses):
62
+ global KNOWN_ADDRESSES
63
+ KNOWN_ADDRESSES = known_addresses
64
+ _get_mnemonic()
65
+
66
+ def _get_mnemonic():
67
+ global _MNEMONIC
68
+ if _MNEMONIC is None: _MNEMONIC = Mnemonic("english")
69
+ return _MNEMONIC
70
+
71
+ # ============================================================
72
+ # Crypto Logic
73
+ # ============================================================
74
+ _SECP256K1_N = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
75
+ _HARDENED = 0x80000000
76
+
77
+ def _bip32_derive_child_priv(parent_priv, parent_chain, index):
78
+ if index >= _HARDENED:
79
+ data = b'\x00' + parent_priv + index.to_bytes(4, 'big')
80
+ else:
81
+ pub = coincurve.PrivateKey(parent_priv).public_key.format(compressed=True)
82
+ data = pub + index.to_bytes(4, 'big')
83
+ I = hmac.new(parent_chain, data, hashlib.sha512).digest()
84
+ child_int = (int.from_bytes(I[:32], 'big') + int.from_bytes(parent_priv, 'big')) % _SECP256K1_N
85
+ if child_int == 0: raise ValueError("Invalid child key")
86
+ return child_int.to_bytes(32, 'big'), I[32:]
87
+
88
+ def seed_to_privkey_hd(seed, account_idx=0, address_idx=0):
89
+ I = hmac.new(b"Bitcoin seed", seed, hashlib.sha512).digest()
90
+ key, chain = I[:32], I[32:]
91
+ for idx in [44 + _HARDENED, 60 + _HARDENED, account_idx + _HARDENED, 0, address_idx]:
92
+ key, chain = _bip32_derive_child_priv(key, chain, idx)
93
+ return key
94
+
95
+ def phrase_to_seed(phrase, passphrase=""):
96
+ return _get_mnemonic().to_seed(phrase, passphrase=passphrase)
97
+
98
+ # ============================================================
99
+ # Worker Function (Yeh 190 cores par parallel chalega)
100
+ # ============================================================
101
+ def process_phrase_worker(phrase):
102
+ global KNOWN_ADDRESSES
103
+ seed = phrase_to_seed(phrase, PASSPHRASE)
104
+ matches_found = []
105
+ paths_checked = 0
106
+
107
+ for acc_idx in range(ACC_START, ACC_END + 1):
108
+ for addr_idx in range(ADDR_START, ADDR_END + 1):
109
+ paths_checked += 1
110
+ try:
111
+ priv = seed_to_privkey_hd(seed, acc_idx, addr_idx)
112
+ pub = coincurve.PrivateKey(priv).public_key.format(compressed=False)[1:]
113
+ addr = to_checksum_address(keccak(pub)[-20:])
114
+ except Exception:
115
+ continue
116
+
117
+ if SCAN_MODE == "File":
118
+ norm_addr = addr[2:].lower() if addr.startswith("0x") else addr.lower()
119
+
120
+ if norm_addr in KNOWN_ADDRESSES:
121
+ match_details = (
122
+ f"\n{'🎯'*20}\n"
123
+ f"🎯 FILE MATCH FOUND!\n"
124
+ f"Phrase: {phrase}\n"
125
+ f"Path: m/44'/60'/{acc_idx}'/0/{addr_idx}\n"
126
+ f"Private Key: {priv.hex()}\n"
127
+ f"Address: {addr}\n"
128
+ f"{'🎯'*20}\n"
129
+ )
130
+ matches_found.append(match_details)
131
+
132
+ else:
133
+ eth_float, bnb_float, eth_str, bnb_str = get_balances(addr)
134
+ if eth_float > 0 or bnb_float > 0:
135
+ match_details = (
136
+ f"\n{'πŸŽ‰'*20}\n"
137
+ f"πŸŽ‰ MATCH WITH BALANCE!\n"
138
+ f"Phrase: {phrase}\n"
139
+ f"Path: m/44'/60'/{acc_idx}'/0/{addr_idx}\n"
140
+ f"Private Key: {priv.hex()}\n"
141
+ f"Address: {addr}\n"
142
+ f"ETH: {eth_str}\n"
143
+ f"BNB: {bnb_str}\n"
144
+ f"{'πŸŽ‰'*20}\n"
145
+ )
146
+ matches_found.append(match_details)
147
+
148
+ return paths_checked, matches_found
149
+
150
+ # ============================================================
151
+ # CSV File Setup
152
+ # ============================================================
153
+ def load_addresses_from_csv(path):
154
+ if not os.path.exists(path): return None
155
+ print(f"⏳ Loading CSV: {path}")
156
+ start = time.time()
157
+
158
+ addresses = set()
159
+ with open(path, "r", encoding="utf-8", errors="replace") as f:
160
+ for line in f:
161
+ a = line.strip().strip('"').strip("'").lstrip("\ufeff").lower()
162
+ if a.startswith("0x"): a = a[2:]
163
+ if a and len(a) == 40:
164
+ addresses.add(a)
165
+
166
+ elapsed = time.time() - start
167
+ print(f"βœ… Loaded {len(addresses):,} addresses in {elapsed:.1f} seconds.\n")
168
+ return addresses
169
+
170
+ # ============================================================
171
+ # Main
172
+ # ============================================================
173
+ def main():
174
+ global_start = time.time()
175
+
176
+ known_addresses = None
177
+ if SCAN_MODE == "File":
178
+ known_addresses = load_addresses_from_csv(CSV_FILE)
179
+ if not known_addresses:
180
+ print(f"❌ CSV File nahi mili ya khali hai: {CSV_FILE}")
181
+ return
182
+
183
+ print("=" * 60)
184
+ print(f"πŸ” HD Wallet Scanner (Parallel: {NUM_WORKERS} Cores)")
185
+ print("=" * 60)
186
+ print(f"πŸ› οΈ Scan Mode: {SCAN_MODE} | Account: {ACC_START}-{ACC_END} | Address: {ADDR_START}-{ADDR_END}")
187
+ print(f"πŸ“ Total Phrases to scan: {NUM_PHRASES}\n")
188
+
189
+ mnemo = _get_mnemonic()
190
+
191
+ # Phrase list generate karein
192
+ phrases_to_check = []
193
+ for i in range(1, NUM_PHRASES + 1):
194
+ if i == 25:
195
+ phrases_to_check.append(MY_TEST_PHRASE)
196
+ else:
197
+ phrases_to_check.append(mnemo.generate(strength=128))
198
+
199
+ total_phrases = len(phrases_to_check)
200
+ phrases_checked = 0
201
+ total_paths_checked = 0
202
+ total_matches = 0
203
+
204
+ def update_progress(completed, total):
205
+ pct = (completed / total) * 100
206
+ sys.stdout.write(f"\r⏳ Scanning Progress: {pct:.1f}% ({completed}/{total})")
207
+ sys.stdout.flush()
208
+
209
+ print(f"πŸš€ Starting {NUM_WORKERS} workers on your Dual-Socket Xeon...\n")
210
+
211
+ try:
212
+ # Linux fork will share the 1.5GB address set across all 190 workers!
213
+ with multiprocessing.Pool(
214
+ processes=NUM_WORKERS,
215
+ initializer=init_worker,
216
+ initargs=(known_addresses,)
217
+ ) as pool:
218
+
219
+ # chunksize=2 distributes work rapidly across both NUMA nodes
220
+ for paths, matches in pool.imap_unordered(process_phrase_worker, phrases_to_check, chunksize=2):
221
+ phrases_checked += 1
222
+ total_paths_checked += paths
223
+
224
+ for match in matches:
225
+ print(match)
226
+ total_matches += 1
227
+
228
+ update_progress(phrases_checked, total_phrases)
229
+
230
+ print()
231
+
232
+ except KeyboardInterrupt:
233
+ print("\n\nπŸ›‘ Script ruk gayi (Ctrl+C).")
234
+ pool.terminate()
235
+ pool.join()
236
+
237
+ global_elapsed = time.time() - global_start
238
+
239
+ print("\n" + "=" * 60)
240
+ print("🏁 RUN SUMMARY")
241
+ print("=" * 60)
242
+ print(f"πŸ“ Phrases checked in THIS run: {phrases_checked}")
243
+ print(f"πŸ”‘ Private Keys generated in THIS run: {total_paths_checked:,}")
244
+ print(f"πŸ“¬ Addresses checked in THIS run: {total_paths_checked:,}")
245
+ print(f"🎯 Matches found in THIS run: {total_matches}")
246
+ print("-" * 60)
247
+ print(f"⏱️ Total time to complete process: {global_elapsed:.2f} seconds")
248
+ print("=" * 60)
249
+
250
+ if __name__ == "__main__":
251
+ main()