|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 zhang206zyx 于 2014-5-26 21:09 编辑
PS: 配合我发的另外一个自动获取代理的Python程序更牛叉!
原为猪八戒的一个人写的,但是当时忙,晚了几天没赶上,现在发出来给大家玩玩吧。
Python版本2.7
- # encoding:utf8
- '''\
- http代理 BY BBDXF 2014-5-15 18:51:50
- 使用方法:
- 1、在IE或者其他软件中开启代理功能。
- 2、设置代理IP为127.0.0.1,端口8080
- 3、运行ProxyOther.py文件
- 说明:
- 此程序只负责代理功能,不负责代理IP和端口的收集测试。
- 如无合适代理可上网自行查找一个。如网页:http://www.youdaili.cn/Daili/guonei/2114.html
- 将 proxyAddr = "14.23.106.197:9000" 替换为合适的代理和端口即可。
- 如果本机127.0.0.1:8080 被占用,可酌情修改为其他端口,如有疑问请与作者联系。
- 环境要求:
- 建议使用最新版的 2.7版本Python, 在环境变量Path中添加Python相关路径。
- '''
- import socket, thread, select
- BUFLEN = 1024*10
- VERSION = 'Python Proxy Sever'+"1.0.1"
- HTTPVER = 'HTTP/1.1'
- proxyAddr = "14.23.106.197:9000"
- class ConnectionHandler:
- def __init__(self, connection, address, timeout):
- self.client = connection
- self.client_buffer = ''
- self.timeout = timeout
- # create a proxy client
- self.target = socket.socket(socket.AF_INET)
- # Transmit the request to others
- strArr = proxyAddr.split(":")
- print strArr
- self.target.connect((strArr[0],int(strArr[1])))
- self.client_buffer = ''
- self._read_write()
- self.target.close()
- self.client.close()
-
- def _read_write(self):
- time_out_max = self.timeout/3
- socs = [self.client, self.target]
- count = 0
- while 1:
- count += 1
- (recv, _, error) = select.select(socs, [], socs, 3)
- if error:
- break
- if recv:
- for in_ in recv:
- try:
- data = in_.recv(BUFLEN)
- if in_ is self.client:
- out = self.target
- else:
- out = self.client
- if data:
- out.send(data)
- count = 0
- except:
- pass
- if count == time_out_max:
- break
- def start_server(host='localhost', port=8080, IPv6=False, timeout=60,
- handler=ConnectionHandler):
- if IPv6==True:
- soc_type=socket.AF_INET6
- else:
- soc_type=socket.AF_INET
- soc = socket.socket(soc_type)
- soc.bind((host, port))
- print "Serving on %s:%d."%(host, port)#debug
- soc.listen(0)
- while 1:
- thread.start_new_thread(handler, soc.accept()+(timeout,))
- if __name__ == '__main__':
- start_server()
复制代码
|
|