-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
MailGrab.py
1150 lines (1118 loc) · 51.8 KB
/
MailGrab.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This Program Will Take Input(url) and Will Harvest The Email Addresses From The Website
# This Is The Main File For The Program
# importing required modules. External Modules Used In This Program Can Be Found In The requirements.txt File
import sys
from bs4 import BeautifulSoup as bs
import requests as r
import urllib.parse as up
from collections import deque as dq
import re
from rich.console import Console
from rich.text import Text
import time
import colorama as c
from termcolor import colored
import cursor
import os
import psutil
import platform
import datetime
import warnings
import logging
if __name__ == "__main__":
if os.name in ("nt", "dos", "ce"):
if os.system("ping -n 1 oceanofanythingofficial.github.io > nul") == 0:
pass
else:
print("Internet Not Connected")
exit()
elif os.name == 'posix':
if os.system("curl -s oceanofanythingofficial.github.io > /dev/null") == 0:
pass
else:
print("Internet Not Connected")
exit()
elif os.name == 'darwin':
if os.system("curl -s oceanofanythingofficial.github.io > /dev/null") == 0:
pass
else:
print("Internet Not Connected")
exit()
"""
Name - MailGrab
Description - Email Harvester Tool
Author - OCEAN OF AMNYTHING
"""
# Configuring Logging System
FORMAT = "[%(lineno)d]: %(levelname)s - %(message)s"
logging.basicConfig(
level=logging.DEBUG, format=FORMAT, datefmt="[%X]", filename="_MailGrabLog.txt", filemode='w', encoding="utf-8"
)
log = logging.getLogger()
log.removeFilter(sys.stderr)
log.propagate = False
date = datetime.datetime.now()
time1 = date.strftime("%H:%M:%S")
log.info("Starting MailGrab")
log.info(
"Srapped Url List By MailGrab A Powerful Email Scraper Tool Made By OCEAN OF ANYTHING")
log.info("This File Contains The Urls Scrapped From The Url Provided By The User")
log.info("https://oceanofanythingofficial.github.io")
log.info("https://github.com/oceanofanythingofficial")
log.info("https://oceanofanythingg.blogspot.com")
log.info(f"Date Of Last Scan: {date}")
log.info(f"Time Of Last Scan: {time1}")
# Creating Universal Signs
# Primarry Sign
sPrimary = Text("[+]")
sPrimary.stylize("bold #0275d8")
log.info("Primary Sign: [+]")
# Warning Sign
sWarning = Text("[!]")
sWarning.stylize("bold #eed202")
log.info("Warning Sign: [!]")
# Danger Sign
sDanger = Text("[!]")
sDanger.stylize("bold #d9534f")
log.info("Danger Sign: [!]")
# Success Sign
sSuccess = Text("[+]")
sSuccess.stylize("bold #5fd700")
log.info("Success Sign: [+]")
# info Sign
sInfo = Text("[+]")
sInfo.stylize("bold #5bc0de")
log.info("Info Sign: [+]")
# success Input Sign
sInput = Text("[?] ")
sInput.stylize("bold #00ff00")
log.info("Input Sign: [?]")
# initializing rich console and coloroma
console = Console(record=True)
c.init(autoreset=True)
# universal Variables
__author__ = Text("OCEAN OF ANYTHING")
__author__.stylize("bold yellow")
__email__ = Text("[email protected]")
__email__.stylize("bold white")
# Check If The User Is Connected To The Internet
if r.get("https://oceanofanythingofficial.github.io") == None:
log.error("Program Closing No Internet Connection")
console.print(sDanger + " You Are Not Connected To The Internet")
log.error("You Are Not Connected To The Internet")
console.print(
sInfo + " Please Connect To The Internet To Continue Using This Program")
log.info("Please Connect To The Internet To Continue Using This Program")
console.print(sInfo + " Press Enter To Exit", end="")
input('')
log.info("Press Enter To Exit")
sys.exit()
elif r.get("https://oceanofanythingofficial.github.io") != None:
pass
else:
pass
# Preventing Creation Of __pycache__ Folder
warnings.filterwarnings("ignore", category=DeprecationWarning)
sys.dont_write_bytecode = True
# chexk if exists __pycache__ folder if yes delete it
if os.path.exists("__pycache__"):
log.info("__pycache__ Folder Exists")
log.info("__pycache__ Folder Exists")
log.info("Deleting __pycache__ Folder")
os.system("rm -rf __pycache__")
log.info("__pycache__ Folder Deleted")
pass
else:
pass
# Functions And Classes
# Banner
class BANNER:
def __init__(self):
console.print(
Text(" _______ _______ _________ _ ", "bold green"), end=""
)
console.print(
Text(" ", "bold red"), end="\n")
console.print(
Text("( )( ___ )\__ __/( \ ", "bold green"), end=""
)
console.print(
Text(" ", "bold red"), end="\n")
console.print(
Text("| () () || ( ) | ) ( | ( ", "bold green"), end=""
)
console.print(
Text(" ", "bold red"), end="\n")
console.print(
Text("| || || || (___) | | | | | ", "bold green"), end=""
)
console.print(
Text(" ________ ___. ", "bold red"), end="\n")
console.print(
Text("| |(_)| || ___ | | | | | ", "bold green"), end=""
)
console.print(
Text(" / _____/___________ \_ |__ ", "bold red"), end="\n")
console.print(
Text("| | | || ( ) | | | | | ", "bold green"), end=""
)
console.print(
Text("/ \ __\_ __ \__ \ | __ \ ", "bold red"), end="\n")
console.print(
Text("| ) ( || ) ( |___) (___| (____/\ ", "bold green"), end=""
)
console.print(
Text("\ \_\ \ | \// __ \| \_\ \ ", "bold red"), end="\n")
console.print(
Text("|/ \||/ \|\_______/(_______/ ", "bold green"), end=""
)
console.print(
Text(" \______ /__| (____ /___ / ", "bold red"), end="\n")
console.print(
Text(" ", "bold green"), end=""
)
console.print(
Text(" \/ \/ \/ ", "bold red"), end="\n")
console.print(Text("Mail", "bold Green"), end="")
console.print(Text("Grab", "bold red"), end="")
console.print(
Text(" A Powerful Email Harvester Tool", "bold blue"), end="")
console.print(Text(" By OCEAN OF ANYTHING",
"bold yellow"), end="\n")
console.print(Text("", "bold red"))
console.print(Text("", "bold red"))
def ordered_set(in_list):
out_list = []
added = set()
for val in in_list:
if not val in added:
out_list.append(val)
added.add(val)
return out_list
# coloring block
block = colored("█", "green")
# Progress Bar
def progressBar(
iterable, prefix="", suffix="", decimals=1, length=100, fill=block, printEnd="\r"
):
"""
Call in a loop to create terminal progress bar
@params:
iterable - Required : iterable object (Iterable)
prefix - Optional : prefix string (Str)
suffix - Optional : suffix string (Str)
decimals - Optional : positive number of decimals in percent complete (Int)
length - Optional : character length of bar (Int)
fill - Optional : bar fill character (Str)
printEnd - Optional : end character (e.g. "\r", "\r\n") (Str)
"""
cursor.hide()
total = len(iterable)
# Progress Bar Printing Function
def printProgressBar(iteration):
percent = ("{0:." + str(decimals) + "f}").format(
100 * (iteration / float(total))
)
filledLength = int(length * iteration // total)
hStick = colored("-", "green")
bar = fill * filledLength + hStick * (length - filledLength)
bar2 = Text(bar, style="bold, green")
stick = colored("|", "green")
print(
f"\r{prefix} {stick}{bar2}{stick} {percent}% {suffix}", end=printEnd)
# Initial Call
printProgressBar(0)
# Update Progress Bar
for i, item in enumerate(iterable):
yield item
printProgressBar(i + 1)
# Print New Line on Complete
print("\n")
cursor.show()
def MAILGRAB():
if 1 < 2:
# Now Check If The _inputUrls.txt File Is Empty Or Not. If Empty Then Pass The Program
# if exists _inputUrls.txt file then open it
f = open("_inputUrls.txt", "r")
# Read The Content Of The Text File And Append It To An Empty List
# Creating A Empty String For Store The Urls
urlListFromTxtFile = []
# Now Reading The Content Of The Text File And Append It To The List By Replacing \n With ,
for line in f:
urlListFromTxtFile.append(line.strip())
# Closing The File
f.close()
# Replacing Blank Lines And Spaces With , From urlListFromTxtFile
if '' in urlListFromTxtFile:
urlListFromTxtFile.remove('')
elif ' ' in urlListFromTxtFile:
urlListFromTxtFile.remove(' ')
urlListFromTxtFile.remove('')
elif '\n' in urlListFromTxtFile:
urlListFromTxtFile.remove('\n')
urlListFromTxtFile.remove('')
elif '\r' in urlListFromTxtFile:
urlListFromTxtFile.remove('\r')
urlListFromTxtFile.remove('')
elif '\t' in urlListFromTxtFile:
urlListFromTxtFile.remove('\t')
urlListFromTxtFile.remove('')
elif '\r\n' in urlListFromTxtFile:
urlListFromTxtFile.remove('\r\n')
urlListFromTxtFile.remove('')
elif '\t\n' in urlListFromTxtFile:
urlListFromTxtFile.remove('\t\n')
urlListFromTxtFile.remove('')
elif "" in urlListFromTxtFile:
urlListFromTxtFile.remove("")
else:
pass
urlListFromTxtFile = [x.strip()
for x in urlListFromTxtFile if x.strip()]
urlListFromTxtFile = ordered_set(urlListFromTxtFile)
# Now Printing The Banner
try:
BANNER()
except Exception as e:
console.print(sDanger + "Error: {}".format(e))
console.print(sInfo + "Error While Printing The Banner")
log.warning("Error: {}".format(e))
log.info("Error While Printing The Banner")
# Now Take Each Url From The List And Harvest The Email From The Url and The url's subdomains
# Taking Input From The User For The Depth Of The Search
console.print(
sInput + "Enter The Search Depth For Each Url (Max Is 200): ", end="")
depthInput = input()
log.info("User Inputted Depth")
startTimeg = time.time()
while True:
while True:
# checking the input is float or not
if type(depthInput) == float:
console.print(sWarning + " Input Cannot Be A Float!")
log.warn("User Entered Invalid Depth")
console.print(
sInput + "Enter The Search Depth For Each Url (Max Is 200): ", end="")
depthInput = input()
log.info("User Inputted Depth")
else:
break
while True:
# checking the input is digit or not, if yes breal while loop
if depthInput.isdigit():
depthInput = int(depthInput)
break
# checking the input is digit or not, if not continuing while loop
elif not depthInput.isdigit():
console.print(sWarning + " Input Must Be A Number!")
log.warn("User Entered Invalid Depth")
console.print(
sInput + "Enter The Search Depth For Each Url (Max Is 200): ", end="")
depthInput = input()
log.info("User Inputted Depth")
# checking the input is digit or not, else continuing while loop
else:
console.print(sWarning + " Input Must Be A Number!")
log.warn("User Entered Invalid Depth")
console.print(
sInput + "Enter The Search Depth For Each Url (Max Is 200): ", end="")
depthInput = input()
log.info("User Inputted Depth")
if depthInput < 0:
console.print(
sWarning + " Search Depth Cannot Be Negative")
log.warn("User Entered Invalid Depth")
console.print(
sInput + "Enter The Search Depth For Each Url (Max Is 200): ", end="")
depthInput = input()
log.info("User Inputted Depth")
# depth = depthInput
elif depthInput == 0:
console.print(sWarning + " Search Depth Cannot Be Zero")
log.warn("User Entered Invalid Depth")
console.print(
sInput + "Enter The Search Depth For Each Url (Max Is 200): ", end="")
depthInput = input()
log.info("User Inputted Depth")
# depth = depthInput
elif depthInput > 200:
console.print(
sWarning
+ " To Prevent Crashing The Program, Search Depth Cannot Be Greater Than 200"
)
log.warn("User Entered Invalid Depth")
console.print(
sInput + "Enter The Search Depth For Each Url (Max Is 200): ", end="")
depthInput = input()
log.info("User Inputted Depth")
# depth = depthInput
else:
depth = depthInput
break
depth = int(depthInput)
cursor.hide()
console.print(sSuccess + " Search Depth Is Set To: " + str(depth))
log.info("Search Depth Set To: " + str(depth))
scrappedUrls = set()
emails = set()
for url in urlListFromTxtFile:
count = 0
emailCount = 0
# Removing white spaces from the url
url = url.replace(" ", "")
log.info("Removed White Spaces From: {}".format(url))
# Now Check If The Url Is Valid Or Not
if not url.startswith("http"):
outputUrl = "http://" + url
else:
outputUrl = url
# Storing The Url In dq
urls = dq([outputUrl])
date = datetime.datetime.now()
time3 = date.strftime("%H:%M:%S")
scrappedUrlList = [
'Srapped Url List By MailGrab A Powerful Email Scraper Tool Made By OCEAN OF ANYTHING',
'This File Contains The Urls Scrapped From The Url Provided By The User',
'https://oceanofanythingofficial.github.io',
'https://github.com/oceanofanythingofficial',
'https://oceanofanythingg.blogspot.com',
f'Date Of Last Scan: {date}',
f'Time Of Last Scan: {time3}',
'Scrapped Urls:'
' '
]
emailList = [
'Srapped Url List By MailGrab A Powerful Email Scraper Tool Made By OCEAN OF ANYTHING',
'This File Contains The Emails Scrapped From The Url Provided By The User',
'https://oceanofanythingofficial.github.io',
'https://github.com/oceanofanythingofficial',
'https://oceanofanythingg.blogspot.com',
f'Date Of Last Scan: {date}',
f'Time Of Last Scan: {time3}',
'Scrapped Emails:',
' '
]
# Checking The Current Time
startTime = time.time()
depthLimit = str(depthInput)
print("\n\n")
console.print(sSuccess + " Base Url Is Set To: " + url)
log.info("Base Url Set To: " + url)
startTimeg = time.time()
while len(urls):
# preventing the program from crashing
count += 1
if count > depth:
break
url = urls.popleft()
scrappedUrls.add(url)
# formating the url
parts = up.urlsplit(url)
baseUrl = "{}://{}".format(parts.scheme, parts.netloc)
# Formating The Subdomain And Displaying It
path = url[: url.rfind(
"/") + 1] if "/" in parts.path else url
bn = Text(f"[{count}]")
bn.stylize("bold #5bc0de")
pText = Text(" Processing: ")
pText.stylize("bold #d700d7")
cUrl = Text(url)
cUrl.stylize("bold #0087d7")
console.print(bn + pText + cUrl)
# getting the html code from the url
try:
response = r.get(url)
# Error Handling
except r.exceptions.HTTPError as e:
console.print(sDanger + " HTTP Error: {}".format(e))
log.error("HTTP Error: {}".format(e))
log.exception("HTTP Error: {}".format(e))
eUrl = Text(url)
eUrl.stylize("bold #d75f00")
console.print(sInfo + " Skipping Url: {}".format(eUrl))
log.info("Skipping Url: {}".format(eUrl))
console
continue
except r.exceptions.ConnectionError as e:
console.print(
sDanger + " Connection Error: {}".format(e))
log.error("Connection Error: {}".format(e))
log.exception("Connection Error: {}".format(e))
eUrl = Text(url)
eUrl.stylize("bold #d75f00")
console.print(sInfo + " Skipping Url: {}".format(eUrl))
log.info("Skipping Url: {}".format(eUrl))
continue
except r.exceptions.Timeout as e:
console.print(sDanger + " Timeout Error: {}".format(e))
log.error("Timeout Error: {}".format(e))
log.exception("Timeout Error: {}".format(e))
eUrl = Text(url)
eUrl.stylize("bold #d75f00")
console.print(sInfo + " Skipping Url: {}".format(eUrl))
log.info("Skipping Url: {}".format(eUrl))
continue
except r.exceptions.TooManyRedirects as e:
console.print(
sDanger + " Too Many Redirects: {}".format(e))
log.error("Too Many Redirects: {}".format(e))
log.exception("Too Many Redirects: {}".format(e))
eUrl = Text(url)
eUrl.stylize("bold #d75f00")
console.print(sInfo + " Skipping Url: {}".format(eUrl))
log.info("Skipping Url: {}".format(eUrl))
continue
except r.exceptions.RequestException as e:
console.print(
sDanger + " Request Exception: {}".format(e))
log.error("Request Exception: {}".format(e))
log.exception("Request Exception: {}".format(e))
eUrl = Text(url)
eUrl.stylize("bold #d75f00")
console.print(sInfo + " Skipping Url: {}".format(eUrl))
log.info("Skipping Url: {}".format(eUrl))
continue
except Exception as e:
console.print(sDanger + " Exception: {}".format(e))
log.error("Exception: {}".format(e))
log.exception("Exception: {}".format(e))
eUrl = Text(url)
eUrl.stylize("bold #d75f00")
console.print(sInfo + " Skipping Url: {}".format(eUrl))
log.info("Skipping Url: {}".format(eUrl))
continue
# finding the emails in the html code
newEmails = set(
re.findall(
r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", response.text, re.I)
)
emails.update(newEmails)
soup = bs(response.text, features="lxml")
# finding the urls in the html code
for anchor in soup.find_all("a"):
link = anchor.attrs["href"] if "href" in anchor.attrs else ""
if link.startswith("/"):
link = baseUrl + link
elif not link.startswith("http"):
link = path + link
if not link in scrappedUrls:
urls.append(link)
print("\n\n\n")
# Now Showing The Time Taken To Collect Emails And Urls
try:
console.print(
sSuccess +
" Time Taken To Collect Emails: {} MiliSeconds".format(
time.time() - startTimeg)
)
log.info("Time Taken To Collect Emails: {}".format(
time.time() - startTimeg))
console.print(
sSuccess +
" Time Taken To Collect Sub Urls: {} MiliSeconds".format(
time.time() - startTimeg)
)
log.info("Time Taken To Collect Sub Urls: {}".format(
time.time() - startTimeg))
except Exception as e:
console.print(sDanger + " Error: {}".format(e))
log.error("Error: {}".format(e))
console.print(
sInfo + " An Error Ocurred While Printing The Time Taken\n")
log.info("An Error Ocurred While Printing The Time Taken\n")
# appending the emails to a list
for mail in emails:
emailList.append(mail)
# appending the urls to a list
for linkList in scrappedUrls:
scrappedUrlList.append(linkList)
try:
print(" ")
print(" ")
while len(emails):
emailCount += 1
ben = Text(f"[{emailCount}]")
ben.stylize("bold #5fd700")
cEmails = Text(emails.pop())
cEmails.stylize("bold #a8a8a8")
console.print(ben + "Email: " + cEmails)
except Exception as e:
console.print(sDanger + " Error: {}".format(e))
log.error("Error: {}".format(e))
console.print(
sInfo + " An Error Ocurred While Printing The Emails")
log.info("An Error Ocurred While Printing The Emails")
# Saving Emails In A Text File
try:
items = list(range(0, 100))
console.print(
sInfo + "Saving Scrapped Emails In A Text File(_emails.txt)\n")
for item in progressBar(items, prefix="Progress:", suffix="Complete", length=90):
with open("_emails.txt", "w") as f:
for item in emailList:
f.write("%s\n" % item)
f.close()
time.sleep(0.1)
console.print(
sSuccess + " Scrapped Emails Are Successfully Saved!\n\n")
except Exception as e:
console.print(sDanger + " Error: {}".format(e))
log.error("Error: {}".format(e))
console.print(
sInfo + " An Error Ocurred While Saving The Emails")
log.info("An Error Ocurred While Saving The Emails")
# Saving Scrapped Urls In A Text File
try:
items = list(range(0, 100))
console.print(
sInfo + "Saving Scrapped Urls In A Text File(_scrappedUrls.txt)\n")
for item in progressBar(items, prefix="Progress:", suffix="Complete", length=90):
with open("_scrappedUrls.txt", "w") as k:
for item in scrappedUrlList:
k.write("%s\n" % item)
k.close()
time.sleep(0.1)
console.print(
sSuccess + " Scrapped Urls Are Successfully Saved!\n\n")
except Exception as e:
console.print(sDanger + " Error: {}".format(e))
log.error("Error: {}".format(e))
console.print(
sInfo + " An Error Ocurred While Saving The Urls")
log.info("An Error Ocurred While Saving The Urls")
# Now Showing How Many Emails And Urls Are Collected
try:
console.print(
sSuccess + " Number Of Scrapped Emails: {}".format(emailCount))
log.info("Number Of Scrapped Emails: {}".format(emailCount))
console.print(
sSuccess + " Number Of Scrapped Urls: {}".format(len(scrappedUrlList)))
log.info("Number Of Scrapped Urls: {}".format(
len(scrappedUrlList)))
except Exception as e:
console.print(sDanger + " Error: {}".format(e))
log.error("Error: {}".format(e))
console.print(
sInfo + " An Error Ocurred While Printing The Emails And Urls")
log.info("An Error Ocurred While Printing The Emails And Urls")
# Now Showing The Time Taken To Collect Emails And Urls
try:
console.print(
sSuccess +
" Time Taken To Collect Emails: {} MiliSeconds".format(
time.time() - startTime)
)
log.info("Time Taken To Collect Emails: {}".format(
time.time() - startTime))
console.print(
sSuccess +
" Time Taken To Collect Sub Urls: {} MiliSeconds".format(
time.time() - startTime)
)
log.info("Time Taken To Collect Sub Urls: {}".format(
time.time() - startTime))
except Exception as e:
console.print(sDanger + " Error: {}".format(e))
log.error("Error: {}".format(e))
console.print(
sInfo + " An Error Ocurred While Printing The Time Taken\n")
log.info("An Error Ocurred While Printing The Time Taken\n")
# showing How Much system resource is using
try:
console.print(sSuccess + " Current Usage Of System Resource:")
log.info("Current Usage Of System Resource:")
console.print(
sSuccess + " CPU: {}%".format(psutil.cpu_percent()))
log.info("CPU: {}%".format(psutil.cpu_percent()))
console.print(
sSuccess + " RAM: {}%".format(psutil.virtual_memory()[2]))
log.info("RAM: {}%".format(psutil.virtual_memory()[2]))
console.print(
sSuccess + " Disk: {}%".format(psutil.disk_usage("/")[3]))
log.info("Disk: {}%".format(psutil.disk_usage("/")[3]))
console.print(
sSuccess + " Network: {}%".format(psutil.net_io_counters()[0]))
log.info("Network: {}%".format(psutil.net_io_counters()[0]))
console.print(
sSuccess + " Network Speed: {} kbps".format(psutil.net_io_counters()[1]))
log.info("Network Speed: {} kbps".format(
psutil.net_io_counters()[1]))
except Exception as e:
console.print(sDanger + " Error: {}".format(e))
log.error("Error: {}".format(e))
console.print(
sInfo + " An Error Ocurred While Printing The System Resource Used By The Program\n")
log.info(
"An Error Ocurred While Printing The System Resource Used By The Program\n")
# Showing The os Information
try:
console.print(
sSuccess + " OS Information: {}".format(platform.platform()))
log.info("OS Information: {}".format(platform.platform()))
except Exception as e:
console.print(sDanger + " Error: {}".format(e))
log.error("Error: {}".format(e))
console.print(
sInfo + " An Error Ocurred While Printing The OS Information\n")
log.info("An Error Ocurred While Printing The OS Information\n")
# showing the name of the os
try:
console.print(
sSuccess + " OS Name: {}".format(platform.system()))
log.info("OS Name: {}".format(platform.system()))
except Exception as e:
console.print(sDanger + " Error: {}".format(e))
log.error("Error: {}".format(e))
console.print(
sInfo + " An Error Ocurred While Printing The OS Name\n")
log.info("An Error Ocurred While Printing The OS Name\n")
# showing the Current Date And Time in a formal way
try:
console.print(
sSuccess + " Current Date And Time: {}".format(datetime.datetime.now()))
log.info("Current Date And Time: {}".format(time.ctime()))
except Exception as e:
console.print(sDanger + " Error: {}".format(e))
log.error("Error: {}".format(e))
console.print(
sInfo + " An Error Ocurred While Printing The Current Date And Time\n")
log.info(
"An Error Ocurred While Printing The Current Date And Time\n")
console.print(
sSuccess + " All Scrapped Emails And Urls Are Saved In _emails.txt And _scrappedUrls.txt\n")
log.info(
"All Scrapped Emails And Urls Are Saved In _emails.txt And _scrappedUrls.txt\n")
console.print(sSuccess + " Thanks For Using MailGrab!")
console.print(sSuccess + " Made By: " + __author__)
console.print(
sInfo + " If You Have Any Suggestion Or Bug Please Contact Me At: " + __email__)
cursor.show()
console.print(sInfo + " Press Any Key To Exit", end="")
input()
log.info("Thanks For Using MailGrab!")
log.info("Program Ended Successfully")
log.info(
"----------------------------------------------------------------------------------------------------------------------")
sys.exit()
else:
pass
# checking if user provide a text file containing bunch of urls, if not pass the program
# Checking if _inputUrls is a Empty File
if os.path.isfile("_inputUrls.txt") and os.path.getsize("_inputUrls.txt") > 0:
MAILGRAB()
else:
pass
# this code will try to get the emails from the url
count = 0
emailCount = 0
try:
# Showing Banner
BANNER()
log.info("Banner Printed")
# taking url input as a string from user
console.print(sInput + "Enter The Url To Be Scanned: ", end="")
inputUserUrl = str(input())
log.info("User Inputted Url")
# Removing White Spaces From The URL
inputUserUrl = inputUserUrl.replace(" ", "")
log.info("Removed White Spaces From Url")
# checking the user input is a valid url or not. if not then formatting the string as url
while True:
if inputUserUrl == " ":
console.print(sWarning + " Please Enter A Valid Url")
log.warn("User Entered Invalid Url")
console.print(sInput + "Enter The Url To Be Scanned: ", end="")
inputUserUrl = str(input())
log.info("User Inputted Url")
elif inputUserUrl == "":
console.print(sWarning + " Url Cannot Be Blank")
log.warn("User Entered Invalid Url")
console.print(sInput + "Enter The Url To Be Scanned: ", end="")
inputUserUrl = str(input())
log.info("User Inputted Url")
elif " " in inputUserUrl:
console.print(
sWarning + " You Cannot Use White Spaces As/In Url")
log.warn("User Entered Invalid Url")
console.print(sInput + "Enter The Url To Be Scanned: ", end="")
inputUserUrl = str(input())
log.info("User Inputted Url")
else:
inputUserUrl = inputUserUrl.replace(" ", "")
break
if not inputUserUrl.startswith("http"):
userUrl = "http://" + inputUserUrl
else:
userUrl = inputUserUrl
# Taking Input From The User For The Depth Of The Search
console.print(sInput + "Enter The Depth Of The Search: ", end="")
depthInput = input()
log.info("User Inputted Depth")
# checking the input is int or not. if not then taking the input again and again continously in loop until the input is int
while True:
while True:
# checking the input is float or not
if type(depthInput) == float:
console.print(sWarning + " Input Cannot Be A Float!")
log.warn("User Entered Invalid Depth")
console.print(
sInput + "Enter The Depth Of The Search (Max Is 500): ", end="")
depthInput = input()
log.info("User Inputted Depth")
else:
break
while True:
# checking the input is digit or not, if yes breal while loop
if depthInput.isdigit():
depthInput = int(depthInput)
break
# checking the input is digit or not, if not continuing while loop
elif not depthInput.isdigit():
console.print(sWarning + " Input Must Be A Number!")
log.warn("User Entered Invalid Depth")
console.print(
sInput + "Enter The Depth Of The Search (Max Is 500): ", end="")
depthInput = input()
log.info("User Inputted Depth")
# checking the input is digit or not, else continuing while loop
else:
console.print(sWarning + " Input Must Be A Number!")
log.warn("User Entered Invalid Depth")
console.print(
sInput + "Enter The Depth Of The Search (Max Is 500): ", end="")
depthInput = input()
log.info("User Inputted Depth")
if depthInput < 0:
console.print(sWarning + " Search Depth Cannot Be Negative")
log.warn("User Entered Invalid Depth")
console.print(
sInput + "Enter The Depth Of The Search (Max Is 500): ", end="")
depthInput = input()
log.info("User Inputted Depth")
# depth = depthInput
elif depthInput == 0:
console.print(sWarning + " Search Depth Cannot Be Zero")
log.warn("User Entered Invalid Depth")
console.print(
sInput + "Enter The Depth Of The Search (Max Is 500): ", end="")
depthInput = input()
log.info("User Inputted Depth")
# depth = depthInput
elif depthInput > 500:
console.print(
sWarning
+ " To Prevent Crashing The Program, Search Depth Cannot Be Greater Than 500"
)
log.warn("User Entered Invalid Depth")
console.print(
sInput + "Enter The Depth Of The Search (Max Is 500): ", end="")
depthInput = input()
log.info("User Inputted Depth")
# depth = depthInput
else:
depth = depthInput
break
depth = int(depthInput)
# giving the urls to deque
urls = dq([userUrl])
# storing the urls and emails in sets
scrappedUrls = set()
emails = set()
date = datetime.datetime.now()
time2 = date.strftime("%H:%M:%S")
scrappedUrlList = [
'Srapped Url List By MailGrab A Powerful Email Scraper Tool Made By OCEAN OF ANYTHING',
'This File Contains The Urls Scrapped From The Url Provided By The User',
'https://oceanofanythingofficial.github.io',
'https://github.com/oceanofanythingofficial',
'https://oceanofanythingg.blogspot.com',
f'Date Of Last Scan: {date}',
f'Time Of Last Scan: {time2}',
'Scrapped Urls:'
' '
]
emailList = [
'Srapped Url List By MailGrab A Powerful Email Scraper Tool Made By OCEAN OF ANYTHING',
'This File Contains The Emails Scrapped From The Url Provided By The User',
'https://oceanofanythingofficial.github.io',
'https://github.com/oceanofanythingofficial',
'https://oceanofanythingg.blogspot.com',
f'Date Of Last Scan: {date}',
f'Time Of Last Scan: {time2}',
'Scrapped Emails:',
' '
]
os.system("cls")
log.info("Cleared The Screen")
BANNER()
# Checking The Current Time
startTime = time.time()
depthLimit = str(depthInput)
console.print(sSuccess + " Base Url Is Set To: " + userUrl)
log.info("Base Url Set To: " + userUrl)
console.print(sSuccess + " Search Depth Is Set To: " + depthLimit)
log.info("Search Depth Set To: " + depthLimit)
console.print("\n")
while len(urls):
# preventing the program from crashing
count += 1
if count > depth:
break
url = urls.popleft()
scrappedUrls.add(url)
# formating the url
parts = up.urlsplit(url)
baseUrl = "{}://{}".format(parts.scheme, parts.netloc)
# Formating The Subdomain And Displaying It
path = url[: url.rfind("/") + 1] if "/" in parts.path else url
bn = Text(f"[{count}]")
bn.stylize("bold #5bc0de")
pText = Text(" Processing: ")
pText.stylize("bold #d700d7")
cUrl = Text(url)
cUrl.stylize("bold #0087d7")
console.print(bn + pText + cUrl)
# getting the html code from the url
try:
response = r.get(url)
# Error Handling
except r.exceptions.HTTPError as e:
console.print(sDanger + " HTTP Error: {}".format(e))
log.error("HTTP Error: {}".format(e))
log.exception("HTTP Error: {}".format(e))
eUrl = Text(url)
eUrl.stylize("bold #d75f00")
console.print(sInfo + " Skipping Url: {}".format(eUrl))
log.info("Skipping Url: {}".format(eUrl))
console
continue
except r.exceptions.ConnectionError as e:
console.print(sDanger + " Connection Error: {}".format(e))
log.error("Connection Error: {}".format(e))
log.exception("Connection Error: {}".format(e))
eUrl = Text(url)
eUrl.stylize("bold #d75f00")
console.print(sInfo + " Skipping Url: {}".format(eUrl))
log.info("Skipping Url: {}".format(eUrl))
continue
except r.exceptions.Timeout as e:
console.print(sDanger + " Timeout Error: {}".format(e))
log.error("Timeout Error: {}".format(e))
log.exception("Timeout Error: {}".format(e))
eUrl = Text(url)
eUrl.stylize("bold #d75f00")
console.print(sInfo + " Skipping Url: {}".format(eUrl))
log.info("Skipping Url: {}".format(eUrl))
continue
except r.exceptions.TooManyRedirects as e:
console.print(sDanger + " Too Many Redirects: {}".format(e))
log.error("Too Many Redirects: {}".format(e))
log.exception("Too Many Redirects: {}".format(e))
eUrl = Text(url)
eUrl.stylize("bold #d75f00")
console.print(sInfo + " Skipping Url: {}".format(eUrl))
log.info("Skipping Url: {}".format(eUrl))
continue
except r.exceptions.RequestException as e:
console.print(sDanger + " Request Exception: {}".format(e))
log.error("Request Exception: {}".format(e))
log.exception("Request Exception: {}".format(e))
eUrl = Text(url)
eUrl.stylize("bold #d75f00")
console.print(sInfo + " Skipping Url: {}".format(eUrl))
log.info("Skipping Url: {}".format(eUrl))
continue
except Exception as e:
console.print(sDanger + " Exception: {}".format(e))
log.error("Exception: {}".format(e))
log.exception("Exception: {}".format(e))
eUrl = Text(url)
eUrl.stylize("bold #d75f00")
console.print(sInfo + " Skipping Url: {}".format(eUrl))
log.info("Skipping Url: {}".format(eUrl))
continue
# finding the emails in the html code
newEmails = set(
re.findall(
r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", response.text, re.I)
)
emails.update(newEmails)
soup = bs(response.text, features="lxml")
# finding the urls in the html code
for anchor in soup.find_all("a"):
link = anchor.attrs["href"] if "href" in anchor.attrs else ""
if link.startswith("/"):
link = baseUrl + link
elif not link.startswith("http"):
link = path + link
if not link in scrappedUrls:
urls.append(link)
except KeyboardInterrupt:
console.print(
sDanger + " Closing! Because User Interrupted The Program")
log.error("Closing! Because User Interrupted The Program")
console.print(sInfo + " Keyboard Interrupt Detected")
log.info("Keyboard Interrupt Detected")
# appending the emails to a list
for mail in emails:
emailList.append(mail)
# appending the urls to a list
for linkList in scrappedUrls:
scrappedUrlList.append(linkList)
# printing the extracted emails
try:
print(" ")
print(" ")
while len(emails):
emailCount += 1
ben = Text(f"[{emailCount}]")
ben.stylize("bold #5fd700")
cEmails = Text(emails.pop())
cEmails.stylize("bold #a8a8a8")
console.print(ben + "Email: " + cEmails)
except Exception as e: