2

I am wondering if anyone knows how to change the global proxy settings of a windows 10 machine, through python. My goal is it to create a script which requests proxies and then sets them global for the entire machine. So if I open chrome or any Browser the traffic flows through the proxy.

But this technique only effects traffic, which is running through cmd

  1. I tried for Example the netsh function in cmd:

    netsh set proxy ..
    
  2. I also tried starting the chrome browser with the proxy, but that also didn't work, referring to this article: https://winaero.com/blog/override-proxy-settings-google-chrome/

My code until now is only grabbing the proxy from a website with list of proxies.

Thanks

1
  • and what have you tried? StackOverflow is more of a "here's what I did... what did I do wrong" place than a "can you tell me how to code this" place. Commented Apr 24, 2020 at 19:21

1 Answer 1

1

To programmatically set a system wide proxy on windows, you can change the registry, i.e.:

from winreg import *

proxy = "127.0.0.1:8080"
status = 1 # 0 disable 1 enable

keyVal = 'Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings'
key = OpenKey(HKEY_CURRENT_USER, keyVal, 0, KEY_ALL_ACCESS)
SetValueEx(key, "ProxyServer", 0, REG_SZ, proxy)
SetValueEx(key, "ProxyEnable", 0, REG_DWORD, status)
CloseKey(key)

Notes:

In my case, I had to close and re-open Firefox for it to acknowledge the new proxy settings.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you soo much is chrome also affected from this setting ???
All programs should be affected by this settings, as long as they're configured to use the system proxy. On Firefox, the setting is Use system proxy settings, but give it a try and test it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.