Exemplo n.º 1
0
def winproxy(ctx, identifier):
    """The command line function"""
    if identifier is None:
        p = ProxySetting()
        p.registry_read()
        ctx.obj = p
    else:
        p = ProxySetting()
        ctx.obj = p
Exemplo n.º 2
0
def _on():
    """Enable the proxy"""
    # Currently not working on the context object, since the write
    # operation is not bound to the corresponding source!
    p = ProxySetting()
    p.registry_read()
    p.enable = True
    p.registry_write()
Exemplo n.º 3
0
def _reg(subkey, value):
    """Experimental command to read or set the ProxyServer property directly."""
    subkey_map = dict(zip(map(lambda s: s.lower(), _SUBKEYS), _SUBKEYS))
    subkey = subkey_map.get(subkey.lower(), None)
    if subkey is None:
        click.echo(
            click.style(
                "Error! Invalid registry key specified.",
                fg='red', bold=True
            )
        )
        sys.exit(1)
    
    p = ProxySetting()
    p.registry_read()
    
    if value is None:
        # Display current value
        value = p[subkey]
        click.echo("{0}: {1}".format(subkey, value))
    else:
        p[subkey] = value
        p.registry_write()
Exemplo n.º 4
0
def closeproxy():
    # INTERNET_OPTION_REFRESH = 37
    # INTERNET_OPTION_SETTINGS_CHANGED = 39
    # internet_set_option = ctypes.windll.Wininet.InternetSetOptionW
    #
    # internet_set_option(0, INTERNET_OPTION_REFRESH, 0, 0)
    # internet_set_option(0, INTERNET_OPTION_SETTINGS_CHANGED, 0, 0)
    # set_key('ProxyEnable', 0)
    p = ProxySetting()
    p.registry_read()
    p.enable = False
    p.registry_write()
    pobj = psutil.Process(proc.pid)
    for c in pobj.children(recursive=True):
        c.kill()
    pobj.kill()
Exemplo n.º 5
0
def _set(enable, http11, override, proxy, http, https, ftp, socks):
    """Change the current proxy settings"""
    server = None
    if not proxy is None and not proxy == '':
        server = dict(all=proxy)
    else:
        server = {}
        if not http is None and not http == '':
            server['http'] = http
        if not https is None and not https == '':
            server['https'] = https
        if not ftp is None and not ftp == '':
            server['ftp'] = ftp
        if not socks is None and not socks == '':
            server['socks'] = socks
        if server == {}:
            server = None
    click.echo(server)
    
    p = ProxySetting()
    p.registry_read()
    
    changed = False
    if not enable is None:
        p.enable = enable
        changed = True
    if not http11 is None:
        p.http11 = http11
        changed = True
    if not server is None:
        p.server = server
        changed = True
    if not override is None:
        p.override = override
        changed = True
    if changed:
        p.registry_write()
Exemplo n.º 6
0
def openproxy(qw):
    # 改为winproxy简单调用
    p = ProxySetting()
    p.server = dict(http='127.0.0.1:6666', https='127.0.0.1:6666')
    p.enable = True
    p.registry_write()