OP 02 March, 2024 - 12:38 PM
Metamask Ethereum Address Extractor From Logs - Python
Code:
import os
LENGTH = 42
TWO_SYMBOLS = '0x'
PATH_FOR_RESULT = input('Path where to create the result file:\n')
buffer = []
def search():
message = 'Path to start searching log files:\n'
for adress, dirs, files in os.walk(input(message)):
for file in files:
if file.endswith('.log'):
yield os.path.join(adress, file)
def read_from_pathtxt(path):
with open(path, encoding='ansi') as file:
for line in file:
before = line.find('lances"')
after = line.find('"Cur')
print('before: ' + str(before), 'after: ' + str(after), 'delta: ' + str(after-before), file=open(f'{PATH_FOR_RESULT}\\log.txt', 'a', encoding='utf-8'))
if (after - before) < 0 or (after - before) > 1000:
with open(os.path.join(PATH_FOR_RESULT, 'errors.txt'), 'a', encoding='utf-8') as r:
r.write(f'Too big string: {path}' + '\n')
continue
with open(os.path.join(PATH_FOR_RESULT, 'report.txt'), 'a', encoding='utf-8') as file:
file.write(line[before:after] + '\n')
for word in line[before:after].split('\"'):
if len(word) == LENGTH and word.startswith(TWO_SYMBOLS) and word not in buffer:
buffer.append(word)
with open(os.path.join(PATH_FOR_RESULT, 'result.txt'), 'a', encoding='utf-8') as file:
file.write(word + '\n')
with open(os.path.join(PATH_FOR_RESULT, 'result_path.txt'), 'a', encoding='utf-8') as file:
file.write(word + ' - ' + path + '\n')
for i in search():
try:
read_from_pathtxt(i)
except Exception as e:
with open(os.path.join(PATH_FOR_RESULT, 'errors.txt'), 'a', encoding='utf-8') as r:
r.write(str(e) + '\n' + i + '\n')