Windows命令行下来回切换代理的小脚本 - 主要为了Google Chrome

作者:半瓶墨水 链接:http://www.2maomao.com/blog/win-script-for-chrome-proxy/
Python语言: Windows下来回切换代理的小脚本 - 主要为了Google Chrome
#! /usr/bin/env python
# -*- coding: utf-8 -*-

#
# 一个来回切换代理服务器的小脚本
#   用Chrome,切换代理不方便,–proxy-server好像也不顶用
#
# 使用方法:
#   proxytoggle 127.0.0.1:8118
#   执行一次开启,再执行就关闭,再执行又开启,循环往复
#
# 有自己主机的,可以用Tohr Proxy:
#   http://blog.solrex.cn/articles/tohr-the-onion-http-router.html
#
import struct
import _winreg
import sys

root = _winreg.HKEY_CURRENT_USER
proxy_path = r"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
kv_Enable = [
  (proxy_path, "ProxyEnable", 1, _winreg.REG_DWORD),
  (proxy_path, "ProxyServer", sys.argv[1], _winreg.REG_SZ),
]

kv_Disable = [
  (proxy_path, "ProxyEnable", 0, _winreg.REG_DWORD),
  (proxy_path, "ProxyServer", sys.argv[1], _winreg.REG_SZ),
]

hKey = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, proxy_path)
value, type = _winreg.QueryValueEx(hKey, "ProxyEnable")
kv = kv_Enable
if value:
    kv = kv_Disable

for keypath, value_name, value, value_type in kv:
    print "Creating", keypath
    hKey = _winreg.CreateKey (root, keypath)
    _winreg.SetValueEx (hKey, value_name, 0, value_type, value)

  • Share/Bookmark

2 Tweets

1 条评论

  • realfun 八月 14th, 2009 2:36 上午

Windows命令行下来回切换代理的小脚本 - 主要为了Google Chrome: Python语言: Windows下来回切换代理的小脚本 - 主要为了Google Chrome #! /usr/bin/env py.. http://bit.ly/WPih5

This comment was originally posted on Twitter

发表评论

  • :l
  • :)
  • :q
  • :(
  • :^
  • :x
  • :v
  • :D
  • :s
  • :h
  • :e
  • :X
  • :k
  • :w
  • :d
  • :p

注意:评论中需包含至少一个中文字,否则视为无效

Additional comments powered by BackType