鱼C论坛

 找回密码
 立即注册
查看: 2770|回复: 2

[技术交流] Python代理,可换IP

[复制链接]
发表于 2014-5-26 21:07:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 zhang206zyx 于 2014-5-26 21:09 编辑

PS: 配合我发的另外一个自动获取代理的Python程序更牛叉!

原为猪八戒的一个人写的,但是当时忙,晚了几天没赶上,现在发出来给大家玩玩吧。

Python版本2.7

  1. # encoding:utf8
  2. '''\
  3. http代理     BY BBDXF 2014-5-15 18:51:50

  4. 使用方法:
  5.     1、在IE或者其他软件中开启代理功能。
  6.     2、设置代理IP为127.0.0.1,端口8080
  7.     3、运行ProxyOther.py文件

  8. 说明:
  9.     此程序只负责代理功能,不负责代理IP和端口的收集测试。
  10. 如无合适代理可上网自行查找一个。如网页:http://www.youdaili.cn/Daili/guonei/2114.html
  11. 将 proxyAddr = "14.23.106.197:9000" 替换为合适的代理和端口即可。
  12.     如果本机127.0.0.1:8080 被占用,可酌情修改为其他端口,如有疑问请与作者联系。

  13. 环境要求:
  14.     建议使用最新版的 2.7版本Python, 在环境变量Path中添加Python相关路径。
  15. '''

  16. import socket, thread, select

  17. BUFLEN = 1024*10
  18. VERSION = 'Python Proxy Sever'+"1.0.1"
  19. HTTPVER = 'HTTP/1.1'

  20. proxyAddr = "14.23.106.197:9000"

  21. class ConnectionHandler:
  22.     def __init__(self, connection, address, timeout):
  23.         self.client = connection
  24.         self.client_buffer = ''
  25.         self.timeout = timeout
  26.         # create a proxy client
  27.         self.target = socket.socket(socket.AF_INET)
  28.         # Transmit the request to others
  29.         strArr = proxyAddr.split(":")
  30.         print strArr
  31.         self.target.connect((strArr[0],int(strArr[1])))
  32.         self.client_buffer = ''
  33.         self._read_write()
  34.         self.target.close()
  35.         self.client.close()
  36.         
  37.     def _read_write(self):
  38.         time_out_max = self.timeout/3
  39.         socs = [self.client, self.target]
  40.         count = 0
  41.         while 1:
  42.             count += 1
  43.             (recv, _, error) = select.select(socs, [], socs, 3)
  44.             if error:
  45.                 break
  46.             if recv:
  47.                 for in_ in recv:
  48.                     try:
  49.                         data = in_.recv(BUFLEN)
  50.                         if in_ is self.client:
  51.                             out = self.target
  52.                         else:
  53.                             out = self.client
  54.                         if data:
  55.                             out.send(data)
  56.                             count = 0
  57.                     except:
  58.                         pass
  59.             if count == time_out_max:
  60.                 break

  61. def start_server(host='localhost', port=8080, IPv6=False, timeout=60,
  62.                   handler=ConnectionHandler):
  63.     if IPv6==True:
  64.         soc_type=socket.AF_INET6
  65.     else:
  66.         soc_type=socket.AF_INET
  67.     soc = socket.socket(soc_type)
  68.     soc.bind((host, port))
  69.     print "Serving on %s:%d."%(host, port)#debug
  70.     soc.listen(0)
  71.     while 1:
  72.         thread.start_new_thread(handler, soc.accept()+(timeout,))

  73. if __name__ == '__main__':
  74.     start_server()
复制代码


想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2014-5-26 21:09:48 | 显示全部楼层
毫无例外,沙发我坐了!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-5-28 14:30:41 | 显示全部楼层
我要板凳,板凳是我的啊
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-20 13:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表