Python修改IE代理Ip

python如何修改windows系统代理Ip教程如下。

修改原理:

通过修改注册表键值来修改windows浏览器代理ip。

———————————————————

# coding: utf-8

import io, sys, time, os, socket
import _winreg

#输出程序说明
print '''
        proxy_auto 1.0 python script by miketao
        Version:1.0'''

def PrintLine():
    print '-' * 50

def PrintNowip():
    #获取当前IP地址
    ip=(socket.gethostbyname(socket.gethostname()))
    PrintLine()
    print('Now ip is: '+ip)

PrintNowip()
#设置代理设置路径
xpath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, xpath, 0, _winreg.KEY_WRITE)

proxy = '127.0.0.1:8087'
#切换至相应代理
def swithpy():
        # proxy=p_xml.getpip(tree,ip)
        # proxy = ''
        try:
                _winreg.SetValueEx(key, "ProxyEnable", 0, _winreg.REG_DWORD, 1)
                _winreg.SetValueEx(key, "ProxyServer", 0, _winreg.REG_SZ, proxy)
                print("have enable proxy!")
        except Exception as e:
                print("ERROR: " + str(e.args))
        finally:
                None

swithpy()

 

转载随意~:陶醉seo » Python修改IE代理Ip

赞 (56)
分享到:更多 ()