#!/usr/bin/env python # Created by Matteo Rattotti on 13/03/06. # Copyright (c) 2006 Matteo Rattotti. All rights reserved. # Contact matteo.rattotti@gmail.com for any problem # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. """ Get the HTTP proxy for the current location or None if no proxy is define. Old Author: Matteo Merli This file is used within Old Author approvation """ import sys try: from Foundation import NSObject from SystemConfiguration import UNSystemConfigurationDynamicStore _not_present = False # print 'Import ok' except: # print 'PyObjC not present' _not_present = True KEY = ur'Setup:/Network/Service/%s/Proxies' def getProxy(): if _not_present: return None store = UNSystemConfigurationDynamicStore.alloc().initWithName_( u'AllKeys' ) # get the current service ID try: serviceId = store.valueForKey_( u'State:/Network/Global/IPv4' )[ 'PrimaryService' ] except: # print 'No Primary Service defined' return None try: d = store.valueForKey_( KEY % serviceId ) enabled = d['HTTPEnable'] if not enabled: # print 'Proxy is not enabled' return None except: return None proxy = 'http://%s:%u/' % (d['HTTPProxy'], d['HTTPPort']) return proxy if __name__=='__main__': proxy = getProxy() print 'Proxy:', proxy