import io, sys, time, re, os import winreg def enableProxy(IP, Port): proxy = IP + ":" + str(Port) xpath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings" try: key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, xpath, 0, winreg.KEY_WRITE) winreg.SetValueEx(key, "ProxyEnable", 0, winreg.REG_DWORD, 1) winreg.SetValueEx(key, "ProxyServer", 0, winreg.REG_SZ, proxy) except Exception as e: print("ERROR: " + str(e.args)) finally: None def disableProxy(): proxy = "" xpath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings" try: key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, xpath, 0, winreg.KEY_WRITE) winreg.SetValueEx(key, "ProxyEnable", 0, winreg.REG_DWORD, 0) winreg.SetValueEx(key, "ProxyServer", 0, winreg.REG_SZ, proxy) except Exception as e: print("ERROR: " + str(e.args)) finally: None def main(): proxyIP = "10.10.1.2" proxyPort = 123 try: disableProxy() enableProxy(proxyIP, proxyPort) except Exception as e: print("ERROR: " + str(e.args)) finally: pass if __name__ == '__main__': main()
时间: 2024-10-13 11:02:52