码迷,mamicode.com
首页 > 编程语言 > 详细

squid重定向(python 代码)

时间:2014-12-17 14:26:34      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:http   ar   os   sp   on   div   bs   代码   ad   

#!/usr/bin/python2.7

# coding: utf-8
import sys,os,stat
import transport
def redirect_url(line,concurrent):
  list = line.split(‘ ‘)
  if concurrent:
    old_url = list[0]
  else:
    old_url = list[1]
 # f = open(‘/etc/squid3/abc.txt‘,‘w‘)
 # f.write(‘old_url:‘+old_url)
 # f.close()
  new_url = ‘\n‘
  if old_url.endswith(‘.avi/‘):
    new_url = ‘http://www.baidu.com/‘ + new_url
   # f = open(‘/etc/squid3/abc.txt‘,‘w‘)
   # f.write(‘old_url:‘+old_url)
   # f.close()
  elif old_url.endswith(‘.exe/‘):
    new_url = ‘http://www.google.com/‘ + new_url
  return new_url
 
def main(concurrent=True):
  line = sys.stdin.readline().strip()
  while line:
       # f = open(‘/etc/squid3/abc.txt‘,‘w‘)
       # f.write(‘line:‘+line)
       # f.close()
    new_url = redirect_url(line,concurrent)
    id=‘‘
    if concurrent:
      id+=line.split(‘ ‘)[0]+‘ ‘
    new_url = id + new_url
   # f = open(‘/etc/squid3/abc.txt‘,‘w‘)
   # f.write(‘new_url:‘+ new_url)
   # f.close()
    sys.stdout.write(new_url)
    sys.stdout.flush()
    line = sys.stdin.readline().strip()
if __name__==‘__main__‘:
  main(len(sys.argv)>1 and sys.argv[1]==‘-c‘)

 

squid重定向(python 代码)

标签:http   ar   os   sp   on   div   bs   代码   ad   

原文地址:http://www.cnblogs.com/ryuham/p/4169164.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!