Skip to content

Commit

Permalink
Merge pull request #3 from kenchou/master
Browse files Browse the repository at this point in the history
socks set http proxy does not seem to work
  • Loading branch information
vangie committed Oct 15, 2014
2 parents bfe5ec2 + 31b4307 commit db197fd
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions gfwlist2pac.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,27 @@ def printConfigInfo(config):


def fetchGFWList(config):
import socks, socket, urllib2

gfwProxyType = config['gfwProxyType']
if (gfwProxyType == socks.PROXY_TYPE_SOCKS4) or (gfwProxyType == socks.PROXY_TYPE_SOCKS5) or (
gfwProxyType == socks.PROXY_TYPE_HTTP):
socks.setdefaultproxy(gfwProxyType, config['gfwProxyHost'], config['gfwProxyPort'], True, config['gfwProxyUsr'],
config['gfwProxyPwd'])
import socks
import socket
import urllib2

proxy_type = config['gfwProxyType']
proxy_host = config['gfwProxyHost']
proxy_port = config['gfwProxyPort']
proxy_user = config['gfwProxyUsr']
proxy_pwd = config['gfwProxyPwd']

if proxy_type == socks.PROXY_TYPE_SOCKS4 or proxy_type == socks.PROXY_TYPE_SOCKS5:
socks.setdefaultproxy(proxy_type, proxy_host, proxy_port, True, proxy_user, proxy_pwd)
socket.socket = socks.socksocket
elif proxy_type == socks.PROXY_TYPE_HTTP:
http_proxy = '{}:{}'.format(proxy_host, proxy_port)
if proxy_user or proxy_pwd:
http_proxy = '{}:{}@{}'.format(proxy_user, proxy_pwd, http_proxy)

proxy_handler = urllib2.ProxyHandler({'http': http_proxy})
opener = urllib2.build_opener(proxy_handler)
urllib2.install_opener(opener)

if config['debug']:
httpHandler = urllib2.HTTPHandler(debuglevel=1)
Expand Down

0 comments on commit db197fd

Please sign in to comment.