This repository has been archived by the owner on Mar 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgeth_scanner.py
62 lines (53 loc) · 1.57 KB
/
geth_scanner.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
# coding: utf-8
"""
Created by chuwt on 18/4/26.
"""
# os
import asyncio
# third
# self
from eth import ETHClient
class Connector(object):
def __init__(self):
self.queue = asyncio.Queue()
async def get_ips(self):
with open('./ips.txt', 'r+') as f:
while True:
data = f.readline()
if data:
await self.queue.put(data)
else:
await self.queue.put('end')
break
f.close()
async def geth_connector(self):
while True:
if self.queue.empty():
continue
else:
url = await self.queue.get()
if url.startswith('end'):
await self.queue.put('end')
break
else:
try:
data = await ETHClient(url).list_account()
print(data)
except Exception as msg:
print(msg)
finally:
print(url)
async def main(self):
task_list = list()
task_list.append(asyncio.ensure_future(self.get_ips()))
task_list += [asyncio.ensure_future(self.geth_connector()) for _ in range(5)]
await asyncio.wait(task_list)
def run(self):
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(asyncio.ensure_future(self.main()))
finally:
loop.close()
if __name__ == '__main__':
c = Connector()
c.run()