-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscp_tshoot.py
More file actions
executable file
·132 lines (105 loc) · 3.86 KB
/
scp_tshoot.py
File metadata and controls
executable file
·132 lines (105 loc) · 3.86 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
#!/usr/bin/env python3
import subprocess as sp
import os
import requests
import json
import pprint
def check_open_ports(ip):
url = "https://api.geekflare.com/openport"
payload = json.dumps({
"url": "https://" + ip
})
headers = {
'x-api-key': '5e3dc3ec-c890-406c-9120-740fa34829bd',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
port_list = json.loads(response.text)['data']
return(port_list)
def are_spd_ports_open(spd_port, open_ports_list):
spd_port_num = int(spd_port)
spd_port_num2 = spd_port_num + 1
spd_port_num3 = spd_port_num + 3
if spd_port_num in open_ports_list:
print ("Port " + str(spd_port_num) + " is correctly forwarded")
else:
print ("Port " + str(spd_port_num) + " is not forwarded correctly or is blocked by a firewall")
if spd_port_num2 in open_ports_list:
print ("Port " + str(spd_port_num2) + " is correctly forwarded")
else:
print ("Port " + str(spd_port_num2) + " is not forwarded correctly or is blocked by a firewall")
if spd_port_num3 in open_ports_list:
print ("Port " + str(spd_port_num3) + " is correctly forwarded")
else:
print ("Port " + str(spd_port_num3) + " is not forwarded correctly or is blocked by a firewall")
def get_storage_folders(storage_folders):
folders_dict_list = []
for folder in storage_folders:
folders_dict = {}
folders_dict["Used"] = folder.split(" ")[1]
folders_dict["Capacity"] = folder.split(" ")[2]
folders_dict["Used"] = folder.split(" ")[3]
folders_dict["Path"] = folder.split(" ")[5]
folders_dict_list.append(folders_dict)
return (folders_dict_list)
def get_drive_size():
drive_sizes = sp.getoutput("lsblk | grep disk").splitlines()
drive_dict_list = []
for drive in drive_sizes:
drive_dict = {}
drive_dict["Name"] = drive.split()[0]
drive_dict["Size"] = drive.split()[3]
drive_dict_list.append(drive_dict)
return (drive_dict_list)
spd_path = sp.getoutput("find / -name spd -type f 2>/dev/null")
spc_path = sp.getoutput("find / -name spc -type f 2>/dev/null")
metadata_path = sp.getoutput("find / -name consensus -type d 2>/dev/null")
spd_user = sp.getoutput("ps -ef | grep spd")
spc_host_v = sp.getoutput(spc_path + " host -v")
spc = sp.getoutput(spc_path)
public_ip = sp.getoutput("dig +short myip.opendns.com @resolver1.opendns.com")
storage = False
storage_folders = []
lines = spc_host_v.splitlines()
for line in lines:
if "Connectability Status" in line:
connectability_status = line.split(":")[1].strip()
elif "Provider ID" in line:
provider_ID = line.split(":")[1].strip()
elif "Version" in line:
version = line.split(":")[1].strip()
elif "netaddress" in line:
netaddress = line.split(":")[1].strip()
announced_port = line.split(":")[2].strip().split(" ")[0]
elif "collateral" in line:
collateral = line.split(":")[1].strip()
elif "Storage Folders" in line:
storage = True
elif (storage == True) and ("Used" not in line):
storage_folders.append(line)
wallet = False
lines = spc.splitlines()
for line in lines:
if "Synced" in line:
synced = line.split(":")[1].strip()
elif "Wallet" in line:
wallet = True
elif ("Status" in line) and wallet:
status = line.split(":")[1].strip()
wallet = False
port_list = check_open_ports(public_ip)
print ("#######################")#
print ("Your public IP address is: " + public_ip)
print ("SPD is running on port " + announced_port)
are_spd_ports_open(announced_port, port_list)
if "Host appears to be working" in connectability_status:
print ("SPD is working fine")
elif "connectable" in connectability_status:
print ("SPD not working, check port forwarding")
else:
print ("SPD has a problem")
print("Your open ports are as follows:")
for port in port_list:
print(port)
pprint.pprint(get_storage_folders(storage_folders))
pprint.pprint(get_drive_size())