吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 574|回复: 3
收起左侧

[Python 原创] Python-切换代{过}{滤}理脚本

[复制链接]
kodesu 发表于 2024-5-7 18:54
Windows系统无法根据不同的SSID来切换代{过}{滤}理服务器,导致可能某些环境下配置的本地代{过}{滤}理服务器ip会应用到其他的网络里面去,导致访问网页错误,微软的这个做法真的十分愚蠢,所以我弄了个脚本能够在这些情况下自动切换代{过}{滤}理服务器而不用跑设置里面找半天,话不多说,开始
##

原理

修改注册表让代{过}{滤}理设置自动化生效
注册表路径: HKEY_CURRENT_USER/Software\Microsoft\Windows\CurrentVersion\Internet Settings,通过修改注册表直接让代{过}{滤}理服务器生效

代码实现

from winreg import OpenKey, SetValueEx, QueryValueEx, CloseKey, HKEY_CURRENT_USER, KEY_ALL_ACCESS, REG_DWORD, REG_SZ

# 配置常量
PROXY_IP = '192.168.5.250'
PROXY_PORT = '7890'
BYPASS_LIST = ['<local>', '*.steamchina.com', 'csgo.wmsj.cn', 'dota2.wmsj.cn', 'wmsjsteam.com', 'dl.steam.clngaa.com', 'dl.steam.ksyna.com', 'st.dl.bscstorage.net', 'st.dl.eccdnx.com', 'st.dl.pinyuncloud.com', 'steampipe.steamcontent.tnkjmec.com', 'steampowered.com.8686c.com', 'steamstatic.com.8686c.com', 'xz.pphimalayanrt.com', 'steampipe-kr.akamaized.net', 'steampipe-partner.akamaized.net', 'steampipe.akamaized.net', '.steamcontent.com', 'localhost', '127.*', '10.*', '224.*', '239.*', '172.16-31.*', '192.168.*']

def toggle_proxy(proxy_ip, proxy_port, bypass_list):
    # 打开Internet Settings注册表键
    internet_settings = OpenKey(HKEY_CURRENT_USER,
        r'Software\Microsoft\Windows\CurrentVersion\Internet Settings',
        0, KEY_ALL_ACCESS)
    print("打开Internet Settings注册表键")

    # 检查代{过}{滤}理是否已启用
    proxy_enabled = QueryValueEx(internet_settings, 'ProxyEnable')[0]

    if proxy_enabled:
        # 如果代{过}{滤}理已启用,禁用代{过}{滤}理
        SetValueEx(internet_settings, 'ProxyEnable', 0, REG_DWORD, 0)
        print("代{过}{滤}理已禁用")
    else:
        # 如果代{过}{滤}理未启用,启用代{过}{滤}理
        SetValueEx(internet_settings, 'ProxyEnable', 0, REG_DWORD, 1)
        print("代{过}{滤}理已启用")

        # 设置代{过}{滤}理服务器和端口
        proxy_server = f'{proxy_ip}:{proxy_port}'
        SetValueEx(internet_settings, 'ProxyServer', 0, REG_SZ, proxy_server)
        print(f"设置代{过}{滤}理服务器和端口为:{proxy_server}")

        # 设置不使用代{过}{滤}理的地址
        bypass = ';'.join(bypass_list)
        SetValueEx(internet_settings, 'ProxyOverride', 0, REG_SZ, bypass)
        print(f"设置不使用代{过}{滤}理的地址为:{bypass}")

    # 关闭注册表键
    CloseKey(internet_settings)
    print("关闭Internet Settings注册表键")

# 使用
toggle_proxy(PROXY_IP, PROXY_PORT, BYPASS_LIST)

免费评分

参与人数 2吾爱币 +2 热心值 +1 收起 理由
shaosir2024 + 1 + 1 我很赞同!
i9420 + 1 热心回复!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

lizy169 发表于 2024-5-8 08:12
这个好,顶一下
shaosir2024 发表于 2024-5-8 08:54
zhmsun 发表于 2024-5-15 13:18
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-20 01:55

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表