Skip to content

Instantly share code, notes, and snippets.

@tesths
Created July 10, 2019 03:03
Show Gist options
  • Save tesths/dd788ad9d37e68aa33bcc5ba7d6bf3c3 to your computer and use it in GitHub Desktop.
Save tesths/dd788ad9d37e68aa33bcc5ba7d6bf3c3 to your computer and use it in GitHub Desktop.
import io, sys, time, re, os
import winreg
import requests
import json
xpath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
def setProxy(enable,proxyIp,IgnoreIp):
try:
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, xpath, 0, winreg.KEY_WRITE)
winreg.SetValueEx(key, "ProxyEnable", 0, winreg.REG_DWORD, enable)
winreg.SetValueEx(key, "ProxyServer", 0, winreg.REG_SZ, proxyIp)
winreg.SetValueEx(key, "ProxyOverride", 0, winreg.REG_SZ, IgnoreIp)
except Exception as e:
print("ERROR: " + str(e.args))
finally:
None
def enableProxy():
proxy_host = '127.0.0.1:1080' # host and port of your proxy
resp = requests.get('http://api.ip.data5u.com/dynamic/get.html?order=xx&json=1&sep=3',
proxies=dict(http='socks5://%s' % proxy_host,
https='socks5://%s' % proxy_host))
data = resp.json()
ip = data["data"][0]["ip"]
port = data["data"][0]["port"]
proxy = str(ip) + ':' + str(port)
print(proxy)
# IgnoreIp = "172.*;192.*;"
print(" Setting proxy")
setProxy(1,proxy,"")
print(" Setting success")
def disableProxy():
print(" Empty proxy")
setProxy(0,"","")
print(" Empty success")
def main():
while(1):
try:
enableProxy()
except Exception as e:
print("ERROR: " + str(e.args))
finally:
pass
time.sleep(10)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment