首页 > 编程语言 > 详细

python修改widows系统代理,爬虫

时间:2021-06-18 09:14:44      阅读:20      评论:0      收藏:0      [点我收藏+]
import winreg


def edit_system_proxy(open_or_close, host, port):
    """
    修改系统代理函数
    :param open_or_close: 是否开启 bool
    :param host: IP
    :param port: 端口
    :return:
    """
    proxy = f"{host}:{port}"
    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", proxy, winreg.REG_SZ),
    ]

    kv_Disable = [
        (proxy_path, "ProxyEnable", 0, winreg.REG_DWORD),
        # (proxy_path, "ProxyServer", proxy, winreg.REG_SZ),
    ]
    if open_or_close:
        kv = kv_Enable
    else:
        kv = kv_Disable
    for keypath, value_name, value, value_type in kv:
        hKey = winreg.CreateKey(root, keypath)
        winreg.SetValueEx(hKey, value_name, 0, value_type, value)


if __name__ == __main__:
    edit_system_proxy(False, "127.0.0.1", "8848")

 

python修改widows系统代理,爬虫

原文:https://www.cnblogs.com/longwenzhang/p/14897970.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!