#!/usr/bin/python2.7
# Coding:utf-8import Sys,os,statimport transportdef 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) & nbsp 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) & nbsp Sys.stdout.flush () line = Sys.stdin.readline (). Strip () if __name__== ' __main__ ': main (len (SYS.ARGV) >1 and sys.argv[1]== '-C ')
Squid redirection (Python code)