-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
171 lines (130 loc) · 6.22 KB
/
main.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
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
167
168
169
170
171
############################################################
""" Required Modules """
############################################################
import os
import requests
try:
import yaml
except ModuleNotFoundError:
try:
print("yaml not found... Automatically installing it for you.")
os.system("python -m pip install pyyaml")
except:
print('Error occurred while installing "yaml", please manually install it by typing "pip install pyyaml".')
############################################################
""" Strings """
############################################################
Green = '\033[1;32;40m'
Yellow = '\033[1;33;40m'
Red = '\033[1;31;40m'
Cyan = '\033[1;36;40m'
White = '\033[0;37;40m'
Logo = f"""{Green}@@@@@@@ @@@ @@@ @@@ @@@@@@@@
@@@@@@@@ @@@ @@@@ @@@ @@@@@@@@@
@@{Yellow}! {Green}@@@ @@{Yellow}! {Green}@@{Yellow}!{Green}@{Yellow}!{Green}@@@ {Yellow}!{Green}@@
{Yellow}!{Green}@{Yellow}! {Green}@{Yellow}!{Green}@ {Yellow}!{Green}@{Yellow}! !{Green}@{Yellow}!!{Green}@{Yellow}!{Green}@{Yellow}! !{Green}@{Yellow}!
{Green}@{Yellow}!{Green}@@{Yellow}!{Green}@{Yellow}! !!{Green}@ {Green}@{Yellow}!{Green}@ {Yellow}!!{Green}@{Yellow}! !{Green}@{Yellow}! {Green}@{Yellow}!{Green}@{Yellow}!{Green}@
{Yellow}!!{Green}@{Yellow}!!! !!! !{Green}@{Yellow}! !!! !!! !!{Green}@{Yellow}!!
!!{Red}: {Yellow}!!{Red}: {Yellow}!!{Red}: {Yellow}!!! {Red}:{Yellow}!! {Yellow}!!{Red}:
{Red}:{Yellow}!{Red}: :{Yellow}!{Red}: :{Yellow}!{Red}: {Yellow}!{Red}:{Yellow}! {Red}:{Yellow}!{Red}: {Yellow}!{Red}::
:: :: :: :: ::: ::::
: : :: : :: :: : """
Settings_Template = """Settings:
Ping_List:
- https://google.com
- https://facebook.com
- https://github.com
- https://msn.com
- # Feel free to add more site here
Default_Value:
Timeout: 5
Version_Control:
Compare: https://raw.githubusercontent.com/RedFurrFox/Simple_Ping/main/.resources/.version"""
############################################################
""" Functions """
############################################################
def Terminal_Cleaner():
if os.name == "posix":
os.system("clear")
else:
os.system("cls")
def Ping(purl, ptimeout):
global reqg1
try:
reqg1 = requests.get(url=purl, timeout=ptimeout)
print(f'[Console][Requests] Target Url: "{purl}" || Status Code: "{reqg1.status_code}" || ✔ [Requests Sent :: You Have Internet Access]')
pass
except requests.ReadTimeout:
print(f'[Console][Requests] Target Url: "{purl}" || Status Code: "{reqg1.status_code}" || ✖ [Requests Blocked :: Auth/Server/DDoS Issue]')
pass
except (requests.ConnectTimeout, requests.ConnectionError):
print(f'[Console][Requests] Target Url: "{purl}" || Status Code: "{reqg1.status_code}" || ✖ [Requests Not Sent :: No Internet]')
pass
except requests.RequestException:
print(f'[Console][Requests] Invalid URl => "{purl}"')
pass
def Check_Tool_Version(ctvurl, ctvtimeout, ctvversion):
global reqg2
try:
requests.get(url="https://camo.githubusercontent.com/12df27140682753703f98aa63ea1afe69472864e061805883667dc107d86efcb/68747470733a2f2f6b6f6d617265762e636f6d2f67687076632f3f757365726e616d653d52656446757272466f78", timeout=ctvtimeout)
reqg2 = requests.get(url=ctvurl, timeout=ctvtimeout).text
if reqg2 == ctvversion:
pass
else:
print('[Console][Tip] Outdated Tool... Please run "git fetch" command inside on this directory to update this tool.\n')
except (requests.ReadTimeout,requests.ConnectTimeout, requests.ConnectionError, requests.RequestException):
pass
def Check_And_Create_Settings_Yaml():
if os.path.exists("settings.yaml"):
pass
else:
with open("settings.yaml", "w") as Writer:
Writer.write(Settings_Template)
Writer.close()
############################################################
""" Data Reader """
############################################################
try:
with open("settings.yaml", "r") as Reader_1:
YML = yaml.safe_load(Reader_1)
Ping_List = YML["Settings"]["Ping_List"]
Timeout = YML["Settings"]["Default_Value"]["Timeout"]
Version_Compare = YML["Settings"]["Version_Control"]["Compare"]
except FileNotFoundError:
with open("settings.yaml", "w") as Writter:
Writter.write(Settings_Template)
Writter.close()
print("[Console][Tips] Missing Required Files Added. Please Re-run The Script.")
exit()
try:
with open(r"../Simple_Ping/.resources/.version", "r") as Reader_2:
Version_Self = Reader_2.read()
except (FileNotFoundError,FileExistsError):
print('[Console][Warning] Missing Required Files For Checking Tool Version... Skipping.\n[Console][Tips] Please run "git fetch" command inside on this directory to update this tool.')
pass
############################################################
""" Main Function """
############################################################
def Main():
print(Logo + Cyan + Version_Self + White)
Check_Tool_Version(ctvurl=Version_Compare, ctvtimeout=Timeout, ctvversion=Version_Self)
print("\n\n[Console][Prompt] Checking Your Internet Please Wait...")
while True:
for Item in Ping_List:
if Item is None:
continue
Ping(purl=Item, ptimeout=Timeout)
print("[Console][Prompt] Session Finished!!! Exiting...")
exit()
############################################################
""" Main Runner """
############################################################
if __name__ == "__main__":
Terminal_Cleaner()
if os.path.isfile("settings.yaml"):
Main()
else:
with open("settings.yaml", "w") as Writter:
Writter.write(Settings_Template)
Writter.close()
Main()