-
Notifications
You must be signed in to change notification settings - Fork 1
/
check.py
65 lines (60 loc) · 1.44 KB
/
check.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
#coding=utf-8
import get,threading,time,requests
def Tcheck():
global proxyTotalNum
for i in range(0,proxyTotalNum):
check()
def check():
global proxyDict,proxyNum,proxyTotalNum,proxyLock
if(proxyNum>proxyTotalNum-1):
return
if(proxyNum%5==0):
print "Finished: "+str(proxyNum)+", in All: "+str(proxyTotalNum)
checkLock.acquire()
host = proxyDict[proxyNum]['host']
port = proxyDict[proxyNum]['port']
proxyNum+=1
checkLock.release()
if(getPage(host,port)):
writeLock.acquire()
f=open('px.txt','a+')
if(f.read().find(host)!=-1):
# print host
f.close()
writeLock.release()
return
f.write(host+"\t"+str(port)+"\n")
f.close()
writeLock.release()
else:
return
def getPage(host,port):
try:
req=requests.get(url="https://www.ipip.net/",timeout=2,proxies={'https':"http://"+host+":"+str(port)})
if(req.text.find(host)):
return True
else:
return False
except Exception,e:
#print e
return False
if __name__ == '__main__':
proxyDict=get.get()
proxyNum=0
proxyTotalNum=len(proxyDict)
checkLock = threading.Lock()
writeLock = threading.Lock()
threads=[]
for i in range(0,5):
# print "A thread start"
threads.append(threading.Thread(target=Tcheck, args= (), name = 'Thread' + str(i)))
for t in threads:
# print "A thread start"
t.setDaemon(True)
t.start()
#for t in threads:
# t.join()
while(proxyNum<proxyTotalNum):
# print "Finished: "+proxyNum+", in All: "+proxyTotalNum
time.sleep(2)
time.sleep(2)