-
Notifications
You must be signed in to change notification settings - Fork 0
/
stabilizer.py
64 lines (52 loc) · 2.38 KB
/
stabilizer.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
#!/usr/bin/env python3
import subprocess
import time
import requests
import json
import signal
import os
if os.geteuid() != 0:
exit("You need to grant root privileges to run this script.")
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def recovery():
network_service_restart = subprocess.Popen(['sudo service NetworkManager restart'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True,)
time.sleep(10)
def internet():
ping = subprocess.Popen(['ping www.google.com -c 2'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True)
time.sleep(10)
return_code = ping.poll()
if return_code == 0:
return True
else:
return False
print("\033c", end="")
print(f"{bcolors.WARNING} ╔──────────────────────────BH's Internet stabilizer ───────────────────────╗{bcolors.ENDC}")
print(f"{bcolors.WARNING} | Internet connection stabilizer for persistent Remote Desktop experience. |{bcolors.ENDC}")
print(f"{bcolors.WARNING} | Coded by Babak Hajizadeh. |{bcolors.ENDC}")
print(f"{bcolors.WARNING} ┖──────────────────────────────────────────────────────────────────────────┙{bcolors.ENDC}")
print(" [i] Internet connection persistency control module started.")
while True:
# uncomment for debug: print(internet())
if not internet():
print(f"{bcolors.WARNING} [!] Internet connection failed!.{bcolors.ENDC}")
print(f"{bcolors.WARNING} Attempting to recovery...{bcolors.ENDC}")
recovery()
while not internet():
recovery()
if internet():
print(f"{bcolors.OKBLUE} [i] Internet connection has been recovered successfully{bcolors.ENDC}")
print(f"{bcolors.OKBLUE} No further actions is needed{bcolors.ENDC}")