-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeile_online_nodes.py
136 lines (119 loc) · 6.81 KB
/
meile_online_nodes.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/env python3
import random
import json
import pymysql
import scrtsxx
import grpc
from grpc import StatusCode
from sentinel_sdk.sdk import SDKInstance
from sentinel_sdk.types import PageRequest, Status
from sentinel_sdk.modules.node import NodeModule
GRPCs = [
{"host" : "grpc.mathnodes.com", "port" : 443, "ssl" : True},
{"host" : "grpc.mathnodes.com", "port" : 9000, "ssl" : False},
{"host" : "grpc.noncompliant.network", "port" : 443, "ssl" : True},
{"host" : "grpc.noncompliant.network", "port" : 9090, "ssl" : False},
{"host" : "grpc.dvpn.me", "port" : 443, "ssl" : True},
{"host" : "grpc.dvpn.me", "port" : 9090, "ssl" : False},
{"host" : "grpc.sentinel.co", "port" : 9090, "ssl" : False},
{"host" : "grpc.ungovernable.dev", "port" : 443, "ssl" : True},
{"host" : "grpc.ungovernable.dev", "port" : 9090, "ssl" : False}
]
TIMEOUT = 30
VERSION = 20240622.214057
class OnlineNodes():
def connDB(self):
db = pymysql.connect(host=scrtsxx.HOST,
port=scrtsxx.PORT,
user=scrtsxx.USERNAME,
passwd=scrtsxx.PASSWORD,
db=scrtsxx.DB,
charset="utf8mb4",
cursorclass=pymysql.cursors.DictCursor
)
return db
def DropTableAndCreateNew(self, db):
drop_query = "DROP TABLE online_nodes;"
c = db.cursor()
c.execute(drop_query)
db.commit()
create_query = '''
CREATE TABLE online_nodes (node_address VARCHAR(100) NOT NULL, moniker VARCHAR(500), country VARCHAR(100), city VARCHAR(100),
latitude DECIMAL(7,4), longitude DECIMAL(7,4), gigabyte_prices VARCHAR(2000), hourly_prices VARCHAR(2000),
bandwidth_down BIGINT UNSIGNED, bandwidth_up BIGINT UNSIGNED, wallet VARCHAR(100), handshake BOOLEAN, connected_peers SMALLINT UNSIGNED,
max_peers SMALLINT UNSIGNED, node_type TINYINT UNSIGNED, node_version VARCHAR(20), PRIMARY KEY(node_address));
'''
c.execute(create_query)
db.commit()
def InsertRow(self, db, q):
c= db.cursor()
c.execute(q)
db.commit()
def QueryAndRepopulateDB(self, db):
grpc_status_code = StatusCode.UNAVAILABLE
while grpc_status_code != StatusCode.OK:
try:
randgrpc = GRPCs[random.randint(0, len(GRPCs) -1)]
print(f"[qn]: Using: {randgrpc}...")
sdk = SDKInstance(randgrpc['host'], randgrpc['port'], ssl=randgrpc['ssl'])
nm = NodeModule(sdk._channel,TIMEOUT,sdk._account,sdk._client)
nodes = nm.QueryNodes(status=Status.ACTIVE, pagination=PageRequest(limit=1000))
grpc_status_code = StatusCode.OK
except (grpc.RpcError, ConnectionError) as e:
print(f"[qn]: {str(e)}")
grpc_status_code = StatusCode.UNAVAILABLE
nodesStatus = sdk.nodes.QueryNodesStatus(nodes)
self.DropTableAndCreateNew(db)
'''value of nodesStatus
('sentnode16gswagztkv4q8h4hc89stk2ndc2avgthc45lpx', '{"success":true,"result":{"address":"sentnode16gswagztkv4q8h4hc89stk2ndc2avgthc45lpx","bandwidth":{"download":166750000,"upload":321125000},"handshake":{"enable":false,"peers":8},"interval_set_sessions":1
0000000000,"interval_update_sessions":6900000000000,"interval_update_status":3300000000000,
"location":{"city":"Bangkok","country":"Thailand","latitude":13.8054,"longitude":100.6751},"moniker":"Mrsilent-317","operator":"sent16gswagztkv4q8h4hc89stk2ndc2avgthwr4xys",
"peers":0,"gigabyte_prices":"52573ibc/31FEE1A2A9F9C01113F90BD0BBCCE8FD6BBB8585FAF109A2101827DD1D5B95B8,9204ibc/A8C2D23A1E6F95DA4E48BA349667E322BD7A6C996D8A4AAE8BA72E190F3D1477,1180852ibc/B1C0DDB14F25279A2026BC8794E12B259F8BDA546A3C5132CCAEE4431CE36783,12274
0ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518,15342624udvpn",
"hourly_prices":"18480ibc/31FEE1A2A9F9C01113F90BD0BBCCE8FD6BBB8585FAF109A2101827DD1D5B95B8,770ibc/A8C2D23A1E6F95DA4E48BA349667E322BD7A6C996D8A4AAE8BA72E190F3D1477,1871892ibc/B1C0DDB14F25279A2026BC8794E12B259F8BDA546A3C5132CCAEE4431CE36783,18897ibc/ED07A3391
A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518,4160000udvpn",
"qos":{"max_peers":250},"type":2,"version":"0.7.1"}}')
'''
for a,d in nodesStatus.items():
if json.loads(d)['success']:
result = json.loads(d)['result']
address = result['address'] # VARCHAR(100)
bandwidth_down = int(result['bandwidth']['download']) # BIGINT
bandwidth_up = int(result['bandwidth']['upload']) # BIGINT
handshake = result['handshake']['enable'] # Boolean
city = result['location']['city'] # VARCHAR(100)
country = result['location']['country'] #VARCHAR(100)
latitude = float(result['location']['latitude']) #DECIMAL(7,4)
longitude = float(result['location']['longitude']) #DECIMAL(7,4)
moniker = result['moniker'] # VARCHAR(200)
wallet = result['operator'] #VARCHAR(100)
peers = int(result['peers']) #SMALLINT
gb_prices = result['gigabyte_prices'] #VARCHAR(2000)
hr_prices = result['hourly_prices'] #VARCHAR(2000)
max_peers = int(result['qos']['max_peers']) #SMALLINT
node_type = int(result['type']) #SMALLINT
node_version = result['version'] #VARCHAR(20)
iquery = '''
INSERT IGNORE INTO online_nodes (node_address, moniker, country, city, latitude, longitude, gigabyte_prices, hourly_prices, bandwidth_down, bandwidth_up, wallet, handshake, connected_peers, max_peers, node_type, node_version)
VALUES ("%s", "%s", "%s", "%s", %.4f, %.4f, "%s", "%s", %d, %d, "%s", "%s", %d, %d, %d, "%s")
''' % (address,
moniker,
country,
city,
latitude,
longitude,
gb_prices,
hr_prices,
bandwidth_down,
bandwidth_up,
wallet,
handshake,
peers,
max_peers,
node_type,
node_version)
self.InsertRow(db, iquery)
if __name__ == "__main__":
on = OnlineNodes()
db = on.connDB()
on.QueryAndRepopulateDB(db)