zoukankan      html  css  js  c++  java
  • squid重定向(python 代码)

    #!/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 = ' '
      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')
  • 相关阅读:
    ansible——playbook conditions条件判断
    ansible——playbook lookups从插件加载变量
    ansible——playbook循环
    lombok注解
    集合与集合取笛卡尔积
    List排列组合
    synchronized初识
    java IO与NIO
    文件I/O和标准I/O
    双数据源配置
  • 原文地址:https://www.cnblogs.com/ryuham/p/4169164.html
Copyright © 2011-2022 走看看