美文网首页
编程动态修改iOS http代理

编程动态修改iOS http代理

作者: 超哥__ | 来源:发表于2019-01-06 01:02 被阅读0次

    环境:当然是越狱后才有可能!!!
    经过研究,发现iOS系统设置会将配置写入/Library/Preferences/SystemConfiguration/preferences.plist,而系统服务和设置进程本身会根据该文件进行同步。所以定期检查&修改该文件即可实现所有iOS系统设置

    下面是实际代码python:

    def changeproxy(paramdict):
        '''
            proxymode: close | manual:proxyhost+proxyport | auto:proxyurl
        '''
        ssh_scp_get('/Library/Preferences/SystemConfiguration/preferences.plist', 'preferences.plist')
        preferences = readPlist('preferences.plist')
        currentset = preferences['CurrentSet'].replace('/Sets/', '')
        service_en0 = ''
        serviceorder = preferences['Sets'][currentset]['Network']['Global']['IPv4']['ServiceOrder']
        for service in serviceorder:
            devicename = preferences['NetworkServices'][service]['Interface']['DeviceName']
            if 'en0' == devicename:
                service_en0 = service
        serviceobj = preferences['NetworkServices'][service_en0]
        if paramdict['proxymode'] == 'close':
            serviceobj['Proxies'] = {
                'FTPPassive': 1, 
                'ExceptionsList': [
                    '*.local', 
                    '169.254/16'
                ]
            }
        elif paramdict['proxymode'] == 'manual':
            serviceobj['Proxies'] = {
                'HTTPProxy': paramdict['proxyhost'], 
                'HTTPPort': paramdict['proxyport'], 
                'HTTPSProxy': paramdict['proxyhost'], 
                'HTTPSPort': paramdict['proxyport'],
                'HTTPEnable': 1, 
                'HTTPSEnable': 1, 
                'FTPPassive': 1,
                'ExceptionsList': [
                    '*.local', 
                    '169.254/16'
                ]
            }
        elif paramdict['proxymode'] == 'auto':
            serviceobj['Proxies'] = {
                'FTPPassive': 1, 
                'ExceptionsList': [
                    '*.local', 
                    '169.254/16'
                ], 
                'ProxyAutoConfigEnable': 1, 
                'ProxyAutoConfigURLString': paramdict['proxyurl']
            }
        writePlist(preferences, 'preferences.plist', binary=True)
        ssh_scp_put('preferences.plist', '/Library/Preferences/SystemConfiguration/preferences.plist')
    

    相关文章

      网友评论

          本文标题:编程动态修改iOS http代理

          本文链接:https://www.haomeiwen.com/subject/rtyjrqtx.html