Last active
April 26, 2019 10:00
-
-
Save lloc/5868367 to your computer and use it in GitHub Desktop.
Configure GitHub for a connection trough a proxy with a pacfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
The config.ini contains something like: | |
[Proxy] | |
proxy = http://YOURPROXY/proxy.pac | |
user = YOURUSER | |
pass = YOURPASS | |
local = proxy.pac | |
url = http://github.com | |
short = github.com | |
""" | |
import urllib2, re, os | |
from ConfigParser import SafeConfigParser | |
import pacparser # http://code.google.com/p/pacparser/ | |
config = SafeConfigParser() | |
config.read(os.path.join(os.path.dirname(__file__), 'config.ini')) | |
localpac = config.get('Proxy', 'local') | |
remotepac = urllib2.urlopen(config.get('Proxy', 'proxy')) | |
output = open(localpac, 'w') | |
output.write(remotepac.read()) | |
output.close() | |
pacstring = pacparser.just_find_proxy( | |
localpac, | |
config.get('Proxy', 'url'), | |
config.get('Proxy', 'short') | |
) | |
m = re.match(r'PROXY ([0-9:.]+);', pacstring) | |
proxystr = 'http://%s:%s@%s' % ( | |
config.get('Proxy', 'user'), | |
config.get('Proxy', 'pass'), | |
m.group(1) | |
) | |
#os.system('set http_proxy=%s' % proxystr) | |
#os.system('set https_proxy=%s' % proxystr) | |
os.system('setx http_proxy "%s"' % proxystr) | |
os.system('setx https_proxy "%s"' % proxystr) | |
os.system('git config --global http.proxy %s' % proxystr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment