-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
286 lines (197 loc) · 8.73 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import requests
import socket as s
import json
import sys
from PyEnhance import Stamps
from urllib.parse import urlparse
Stamp = Stamps.Stamp
Input = Stamp.Input
Output = Stamp.Output
Error = Stamp.Error
Info = Stamp.Info
Warn = Stamp.Warn
PositiveStatusCodes = [200, 201, 202, 203, 204, 205, 206,
300, 301, 302, 303, 304, 305, 307,
308, 401]
def Main():
global URL
SpecialCharacters = [
'!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-',
'.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^',
'_', '`', '{', '|', '}', '~'
]
URL = input(f"{Input} Website URL: ") # Takes the url that will be used in the search's
print('\n')
def BasicInfo():
def Stage1():
def FetchTLDS():
global TLDSs
global TLDS
TLDSs = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt"
response = requests.get(TLDSs)
response.raise_for_status()
# The file uses line breaks for each TLD, and we filter out comments which start with '#'
TLDS = [line.strip().lower() for line in response.text.splitlines() if not line.startswith('#')]
FetchTLDS()
def CheckTLDS():
global TLDSValid
global URL
TLDSValid = False
for i in TLDS:
if URL.endswith("/"):
URL = URL[:-1]
if URL.endswith(i):
TLDSValid = True
print(f"{Info} URL has a valid TLDS (.com, .org, .xyz, etc.)")
break
if TLDSValid is False:
input(f"{Error} URL does not have a valid TLDS Do you want to continue? [Y/N] ")
if input == "y" or "Y":
print("Continuing...")
else:
print("Exiting...")
sys.exit()
CheckTLDS()
def IsURLAnIP():
global IsURLAnIPOutput
try:
s.inet_aton(URL)
IsURLAnIPOutput = True
if IsURLAnIPOutput == True:
print(f"{Info} URL is an IP address")
except s.error:
IsURLAnIPOutput = False
if IsURLAnIPOutput == False:
print(f"{Info} URL is not an IP address")
IsURLAnIP()
def Refactor(URL): # defines the refactor function and passes the URL variable as a parameter
global URLHTTPS, URLHTTP # Sets the variables URL HTTPS and URL HTTP to global variables meaning they can be called outside of this function.
global TLDSValid
TLDSValid = False
for i in "https://", "http://":
if URL.startswith(i):
if i == "https://":
URLHTTPS = URL
URLHTTP = URL.replace("https://", "http://")
if i == "http//":
URLHTTP = URL
URLHTTPS = URL.replace("http://", "https://")
break
else:
URLHTTP = f"http://{URL}"
URLHTTPS = f"https://{URL}"
Refactor(URL) # Calls the refactor function with the parameter URL
def Checks():
def HTTPcheck():
global HTTPValid
GetReqStatus = requests.get(url=URLHTTP)
if GetReqStatus.status_code in PositiveStatusCodes:
print(f"{Info} HTTP Valid")
HTTPValid = True
else:
print(f"{URL} is not a valid URL")
HTTPValid = False
def HTTPScheck():
global HTTPSValid
GetReqStatus = requests.get(url=URLHTTPS)
if GetReqStatus.status_code == 200:
print(f"{Info} HTTPS Valid")
HTTPSValid = True
else:
print(f"{URL} is not a valid URL")
HTTPSValid = False
HTTPcheck()
HTTPScheck()
Checks()
Stage1()
def Stage2():
def GetHostName():
global HostnameForIP
o = urlparse(URLHTTP)
HostnameForIP = o.hostname
GetHostName()
def GetWebSiteIP():
global WebSiteIP
WebSiteIP = s.gethostbyname(HostnameForIP)
GetWebSiteIP()
Stage2()
def Stage3():
def GetWebsiteIPInfo():
global Replace
def Country():
global IPinfoCountry
global IPinfoCountryOutput
URL = f'http://ip-api.com/json/{WebSiteIP}?fields=1'
GetIpInfoCountry = requests.get(url=URL)
IPinfoCountry = json.loads(GetIpInfoCountry.text)
IPinfoCountry = json.dumps(IPinfoCountry)
IPinfoCountryOutput = (IPinfoCountry.replace("{", "").replace("}", "")
.replace(":", "").replace("country", "")
.replace('"', ""))
#
Country()
def StateOrRegion():
global IPinfoStateOrRegion
global IPinfoStateOrRegionOutput
URL = f'http://ip-api.com/json/{WebSiteIP}?fields=8'
GetIpInfoStateOrRegion = requests.get(url=URL)
IPinfoStateOrRegion = json.loads(GetIpInfoStateOrRegion.text)
IPinfoStateOrRegion = json.dumps(IPinfoStateOrRegion)
IPinfoStateOrRegionOutput = IPinfoStateOrRegion.replace("{", "").replace("}", "").replace(":", "") \
.replace("regionName", "").replace('"', "")
StateOrRegion()
def City():
global IPinfoCity
global IPinfoCityOutput
URL = f'http://ip-api.com/json/{WebSiteIP}?fields=16'
GetIpInfoCity = requests.get(url=URL)
IPinfoCity = json.loads(GetIpInfoCity.text)
IPinfoCity = json.dumps(IPinfoCity)
IPinfoCityOutput = IPinfoCity.replace("{", "").replace("}", "").replace(":", "") \
.replace("city", "").replace('"', "")
City()
def ISP():
global IPinfoISP
global IPinfoISPOutput
URL = f'http://ip-api.com/json/{WebSiteIP}?fields=512'
GetIPinfoISP = requests.get(url=URL)
IPinfoISP = json.loads(GetIPinfoISP.text)
IPinfoISP = json.dumps(IPinfoISP)
IPinfoISPOutput = IPinfoISP.replace("{", "").replace("}", "").replace(":", "") \
.replace("isp", "").replace('"', "")
ISP()
GetWebsiteIPInfo()
Stage3()
def Stage4():
def Output():
def InfoOutput():
global Info, Warn, Output, Input, Error
print('\n')
print(f"{Output} Hostname: {HostnameForIP}")
print(f"{Output} IP Address: {WebSiteIP}")
print(f"{Output} ISP:{IPinfoISPOutput}")
print(f"{Output} Country:{IPinfoCountryOutput}")
print(f"{Output} State or Region:{IPinfoStateOrRegionOutput}")
print(f"{Output} City:{IPinfoCityOutput}")
InfoOutput()
def InfoOutputTXT():
HOSTNAMEFORTXT = HostnameForIP.replace("www.", "").replace(".com", "")
output = [
f"Hostname: {HostnameForIP} \n",
f"IP Address: {WebSiteIP} \n",
f"ISP:{IPinfoISPOutput} \n",
f"Country:{IPinfoCountryOutput} \n",
f"State or Region:{IPinfoStateOrRegionOutput}\n",
f"City:{IPinfoCityOutput}\n"
]
with open(f"{HOSTNAMEFORTXT}.txt", 'w') as file:
file.writelines(output)
InfoOutputTXT()
Output()
Stage4()
BasicInfo()
Main()
# WebsiteInfoGraber Beta 1.4.1
# Gets basic Info from a website URL
# Not A Bird
# CEO of Bird Inc.