import socket,threading,os,sys,queue,re
socket.setdefaulttimeout(5)
path=sys.path[0]
if os.path.isfile(path):
path=os.path.split(path)[0]
domain=
'
www.baidu.com
'
que=queue.Queue()
tno=20
a=open(path+r
'
\proxy.txt
').read().strip().split()
for i
in a:
que.put(i.split(
'
:
'))
data=
'''
GET http://www.baidu.com/ HTTP/1.1
Host: www.baidu.com
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11
Accept: */*
Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3
'''
def geturl():
while True:
if que.empty():
return False
proxy,port=que.get(timeout=1)
try:
s=socket.socket()
s.connect((proxy,int(port)))
s.send(data.encode())
da=s.recv(1024).decode(
'
utf8
',
'
ignore
')
if
'
200 OK
'
in da:
open(path+r
'
\proxyok.txt
',
'
at
').write(proxy+
'
:
'+port+
'
\n
')
print(proxy+
'
:
'+port,
'
可用
')
except Exception as err:
print(proxy,port,err)
print(proxy,port,err,file=open(path+r
'
\err.txt
',
'
at
'))
pass
finally:
s.close()
for i
in range(tno):
threading.Thread(target=geturl).start()