-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathipOverview.py
More file actions
executable file
·166 lines (138 loc) · 4.48 KB
/
ipOverview.py
File metadata and controls
executable file
·166 lines (138 loc) · 4.48 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python3
import json, requests, re, argparse
from datetime import datetime
from rshost import rsHost
debug = False
if __name__ == "__main__":
dump = False
parser = argparse.ArgumentParser()
parser.add_argument("--dump", "-d", help="dump all IPs", action="store_true")
rs = rsHost(debug, parser)
args, _ = parser.parse_known_args()
if args.dump:
dump = True
friends = rs.sendRequest("/rsPeers/getFriendList")["sslIds"]
# IPv4
v4 = 0
v4c = 0
v4i = 0
v4o = 0
# IPv6
v6 = 0
v6c = 0
v6i = 0
v6o = 0
# Tor
t = 0
tc = 0
ti = 0
to = 0
# I2P
i = 0
ic = 0
ii = 0
io = 0
# TCP/UDP
tcpi = 0
tcpo = 0
udpi = 0
udpo = 0
for friend in friends:
req = {"sslId": friend}
details = rs.sendRequest("/rsPeers/getPeerDetails", req)["det"]
ser = 1 if details["actAsServer"] else 0
if details["isHiddenNode"]:
con = 0 if details["connectAddr"] == "" else 1
if dump:
diff = datetime.now() - datetime.fromtimestamp(details["lastConnect"])
print(
"sslid: {} HIDDEN {} {} {}".format(
friend,
"ON " if con == 1 else "OFF",
details["hiddenNodeAddress"],
diff,
)
)
# count peers
if details["hiddenNodeAddress"].endswith(".onion"):
t = t + 1
tc = tc + con
else:
i = i + 1
ic = ic + con
if con == 0:
continue
# count online
if details["hiddenNodeAddress"].endswith(".onion"):
to = to + (1 - ser)
ti = ti + ser
else:
io = io + (1 - ser)
ii = ii + ser
else:
if dump and details["ipAddressList"] != []:
print(
"sslid: {} CLEAR {} [{}]".format(
friend,
"ON " if details["connectAddr"] != "" else "OFF",
details["ipAddressList"],
)
)
# count IPs
ips = details["ipAddressList"]
for ip in ips:
if ip[3] == "4":
v4 = v4 + 1
else:
v6 = v6 + 1
if details["connectAddr"] == "":
continue
# count online
if re.search("^\d+.\d+.\d+.\d+$", details["connectAddr"]) != None:
v4c = v4c + 1
v4o = v4o + (1 - ser)
v4i = v4i + ser
else:
v6c = v6c + 1
v6o = v6o + (1 - ser)
v6i = v6i + ser
# count TCP/UDP
# /* Connect state */
# const uint32_t RS_PEER_CONNECTSTATE_OFFLINE = 0;
# const uint32_t RS_PEER_CONNECTSTATE_TRYING_TCP = 2;
# const uint32_t RS_PEER_CONNECTSTATE_TRYING_UDP = 3;
# const uint32_t RS_PEER_CONNECTSTATE_CONNECTED_TCP = 4;
# const uint32_t RS_PEER_CONNECTSTATE_CONNECTED_UDP = 5;
# const uint32_t RS_PEER_CONNECTSTATE_CONNECTED_TOR = 6;
# const uint32_t RS_PEER_CONNECTSTATE_CONNECTED_I2P = 7;
# const uint32_t RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN = 8;
v = details["connectState"]
if v == 4:
tcpo = tcpo + (1 - ser)
tcpi = tcpi + ser
elif v == 5:
udpo = udpo + (1 - ser)
udpi = udpi + ser
def printStat(what: str, all: int, connected: int, num_in: int, num_out: int):
print(
"{:6}{!s:9} (connected: {!s:5} in: {!s:5} out: {!s:3})".format(
what, all, connected, num_in, num_out
)
)
def printStat2(what: str, all: int, num_in: int, num_out: int):
print(
"{:15} (connected: {!s:5} in: {!s:5} out: {!s:3})".format(
what, all, num_in, num_out
)
)
print("Connection statistics:")
printStat("IPv4", v4, v4c, v4i, v4o)
printStat("IPv6", v6, v6c, v6i, v6o)
print("")
print("Hidden services:")
printStat("Tor", t, tc, ti, to)
printStat("I2P", i, ic, ii, io)
print("")
print("TCP/UDP (excluding Tor/I2P):")
printStat2("TCP", tcpi + tcpo, tcpi, tcpo)
printStat2("UDP", udpi + udpo, udpi, udpo)