1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
| import redis import json from xml.etree import ElementTree
def RedisProxyGet(): ConnectString = [] pool = redis.ConnectionPool(host='192.168.10.20', port=6379, db=0, decode_responses=True) use_proxy = redis.Redis(connection_pool=pool) key = use_proxy.hkeys('use_proxy') for temp in key: try: ConnectString.append(json.loads(use_proxy.hget('use_proxy',temp))) except json.JSONDecodeError: pass return ConnectString
def xmlOutputs(data): i = 101 ProxyIDList = []
ProxifierProfile = ElementTree.Element("ProxifierProfile") ProxifierProfile.set("version", str(i)) ProxifierProfile.set("platform", "Windows") ProxifierProfile.set("product_id", "0") ProxifierProfile.set("product_minver", "310")
Options = ElementTree.SubElement(ProxifierProfile, "Options")
Resolve = ElementTree.SubElement(Options, "Resolve") AutoModeDetection = ElementTree.SubElement(Resolve, "AutoModeDetection") AutoModeDetection.set("enabled", "false")
ViaProxy = ElementTree.SubElement(Resolve, "ViaProxy") ViaProxy.set("enabled", "false")
TryLocalDnsFirst = ElementTree.SubElement(ViaProxy, "TryLocalDnsFirst") TryLocalDnsFirst.set("enabled", "false")
ExclusionList = ElementTree.SubElement(Resolve, "ExclusionList") ExclusionList.text = "%ComputerName%; localhost; *.local"
Encryption = ElementTree.SubElement(Options, "Encryption") Encryption.set("mode", 'basic') Encryption = ElementTree.SubElement(Options, "HttpProxiesSupport") Encryption.set("enabled", 'true') Encryption = ElementTree.SubElement(Options, "HandleDirectConnections") Encryption.set("enabled", 'false') Encryption = ElementTree.SubElement(Options, "ConnectionLoopDetection") Encryption.set("enabled", 'true') Encryption = ElementTree.SubElement(Options, "ProcessServices") Encryption.set("enabled", 'false') Encryption = ElementTree.SubElement(Options, "ProcessOtherUsers") Encryption.set("enabled", 'false')
ProxyList = ElementTree.SubElement(ProxifierProfile, "ProxyList") for temp in data: i += 1 Proxy = ElementTree.SubElement(ProxyList, "Proxy") Proxy.set("id", str(i))
if not temp['https']: Proxy.set("type", "HTTP") else: Proxy.set("type", "HTTPS") Proxy.text = str(i) ProxyIDList.append(i)
Address = ElementTree.SubElement(Proxy, "Address") Address.text = temp['proxy'].split(":", 1)[0]
Port = ElementTree.SubElement(Proxy, "Port") Port.text = temp['proxy'].split(":", 1)[1]
Options = ElementTree.SubElement(Proxy, "Options") Options.text = "48"
ChainList = ElementTree.SubElement(ProxifierProfile, "ChainList")
Chain = ElementTree.SubElement(ChainList, "Chain") Chain.set("id", str(i)) Chain.set("type", "simple")
Name = ElementTree.SubElement(Chain, "Name") Name.text="AgentPool"
for temp_id in ProxyIDList: Proxy = ElementTree.SubElement(Chain, "Proxy") Proxy.set("enabled", "true") Proxy.text=str(temp_id) RuleList = ElementTree.SubElement(ProxifierProfile, "RuleList")
Rule = ElementTree.SubElement(RuleList, "Rule") Rule.set("enabled", "true") Name = ElementTree.SubElement(Rule,"Name") Applications = ElementTree.SubElement(Rule,"Applications") Action = ElementTree.SubElement(Rule,"Action")
Name.text="御剑后台扫描工具.exe [auto-created]" Applications.text="御剑后台扫描工具.exe" Action.set("type","Direct")
Rule = ElementTree.SubElement(RuleList, "Rule") Rule.set("enabled", "true") Name = ElementTree.SubElement(Rule,"Name") Targets = ElementTree.SubElement(Rule,"Targets") Action = ElementTree.SubElement(Rule,"Action")
Name.text="Localhost" Targets.text="localhost; 127.0.0.1; %ComputerName%" Action.set("type", "Direct")
Rule = ElementTree.SubElement(RuleList, "Rule") Rule.set("enabled", "true") Name = ElementTree.SubElement(Rule, "Name") Action = ElementTree.SubElement(Rule, "Action") Name.text = "Default" Action.text = "102" Action.set("type", "Proxy")
tree = ElementTree.ElementTree(ProxifierProfile) tree.write("ProxifierConf.ppx", encoding="UTF-8", xml_declaration=True) if __name__ == '__main__': proxy_data = RedisProxyGet() xmlOutputs(proxy_data) print("ProxifierConf.ppx配置文件创建完成....")
|