forked from 3rdIteration/btcrecover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-address-db.py
110 lines (90 loc) · 3.91 KB
/
check-address-db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
# check-address-db.py -- Bitcoin address database creator for seedrecover
# Copyright (C) 2021 Stephen Rothery
#
# This file is part of btcrecover.
#
# btcrecover is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
# btcrecover is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/
from btcrecover import addressset
from btcrecover import btcrseed
import sys,argparse, atexit
from os import path
__version__ = "1.11.0-CryptoGuide"
if __name__ == "__main__":
print("Starting CheckAddressDB", __version__)
parser = argparse.ArgumentParser()
parser.add_argument("--dbfilename", nargs="?", default="addresses.db", help="the name of the database file (default: addresses.db)")
parser.add_argument("--checkaddresses", nargs="*", help="Check whether a single address is present in the addressDB")
parser.add_argument("--checkaddresslist", metavar="PATH", help="Check whether all of the addresses in a list file are present in the addressDB")
parser.add_argument("--suppress-found", action="store_true",
help="Suppress console messages for found addresses")
parser.add_argument("--suppress-notfound", action="store_true",
help="Suppress console messages for not-found addresses")
# Optional bash tab completion support
try:
import argcomplete
argcomplete.autocomplete(parser)
except ImportError:
pass
args = parser.parse_args()
if not path.exists(args.dbfilename):
sys.exit("Address database file not found...")
print("Loading address database ...")
addressdb = addressset.AddressSet.fromfile(open(args.dbfilename, "rb"))
print("Loaded", len(addressdb), "addresses from database ...")
addresses = []
comments = []
if args.checkaddresses:
for address in args.checkaddresses:
addresses.append(address)
comments.append("")
if args.checkaddresslist:
with open(args.checkaddresslist) as addressistfile:
print("Loading: ", args.checkaddresslist)
for line in addressistfile:
if len(line) < 2: continue
if "#" in line:
address, comment = line.split("#")
else:
address = line
comment = ""
addresses.append(address.strip())
comments.append(comment.strip())
checklist = zip(addresses, comments)
found = 0
not_found = 0
checked = 0
for address, comment in checklist:
checked += 1
if (checked % 100000 == 0):
print("Checked:", checked, "addresses in current file,", len(addresses),
"lines in current addresslist")
# Just use wallet base and walletethereum for now
try:
hash160 = btcrseed.WalletBase._addresses_to_hash160s([address]).pop()
except:
#print("Invalid Address in Checklist:", address, comment)
#continue
hash160 = btcrseed.WalletEthereum._addresses_to_hash160s([address]).pop()
if hash160 in addressdb:
found += 1
if not args.suppress_found:
print(address, "Found!", comment)
else:
not_found += 1
if not args.suppress_notfound:
print(address, "Not Found!", comment)
print("Checked", len(addresses), "addresses")
print(found, "Found")
print(not_found, "Not Found")