pyth0n3 Posted August 21, 2011 Report Posted August 21, 2011 (edited) Am plecat de la o singura optiune de switch si m-am bagat putin mai departeAr fi trebui sa iasa putin mai complicat si cu mai multe feature, printre care multiproxy , dar las balta proiectul Schimba proxy in firefox (functioneaza doar pentru cei care au doar un profil de default)Daca cineva vrea sa il modifie , poate sa o faca ,E o versiune Alpha , Pentru documentare:Proxy auto-config - Wikipedia, the free encyclopediaPrefs.js file - MozillaZine Knowledge Base In rest codul nu e caligrafic deoarece am facut diverse modificari in diverse locuriFunctioneaza doar in linux cu firefox#!/usr/bin/python#Date:21.07.2011#Author:Pyth0n3#Purpose: Proxy setup Firefox#Blog: http://pyth0n3.blogspot.com/from __future__ import print_functionimport commandsimport socketimport sysimport oshand = os.getenv('HOME')def display(): print ('''Usage: setproxy.py with: setauto - to set automatic config (required once) noauto - just change proxy option Note:setauto must be set at least once before noauto''') sys.exit()if len(sys.argv) < 2: display()disp1 = 'noauto'disp2 = sys.argv[1]disp3 = 'setauto'while True: if disp2 == disp1 or disp2 == disp3 :break else: display()igot = disp2if igot == 'setauto': hand = os.getenv('HOME') os.chdir(hand) rootdir='.mozilla' for subdir,dirs, files in os.walk(rootdir): for file in files: if file == "prefs.js": file_path = hand + '/' + subdir + '/' + file search_file = open(file_path) match = False for line in search_file: if 'user_pref("network.proxy.type", 2);' in line: match = True break t=match n = 'proxy.pac' if t == True: print ('Already checked , you can run without setauto option') else: f = open (file_path, 'a') f.write('user_pref("network.proxy.autoconfig_url", "file://'+hand+'/'+n+'");\n') f.write('user_pref("network.proxy.type", 2);\n') f.close()checking = commands.getoutput('ps -A')if 'firefox' in checking: print ('Firefox is running , you must restart it to work')#get_host function declarationdef get_host(): while True: my_host = raw_input('Enter proxy here: ') if len(my_host) < 30 : break else: print ('Too large') return my_host#execute get_host herey = get_host()print ('You have entered',str(y))try: socket.inet_aton(y)except socket.error: print ('You have entered an ilegal address, it may not work')#get_port function declarationdef get_port(): while True: try: port = int(raw_input('Enter the port: ' )) if port in range(1023,65535) : break else: print ('Port number out of range ') print ('Must be > 1023 or < 65535 ') except ValueError: print ('Invalid Number') print ('Must be > 1023 or < 65535 ') return port#execute get_port herex = get_port()print ('You have entered: ', x)#get the home directory hand = os.getenv('HOME')os.chdir(hand)#write data to proxy filef = open ('proxy.pac', 'w')f.write ('function FindProxyForURL(url, host)\n')f.write ('{\n')f.write('\treturn "PROXY ' +str(y)+':'+str(x)+'; DIRECT";\n')f.write('}\n')f.close()Download:wget http://sprunge.us/NBQe -O setproxy.py Edited August 21, 2011 by pyth0n3 Quote