基於Proxypool的代理池搭建
阿新 • • 發佈:2021-08-16
Ubuntu下搭建免費代理池
前言
今天在暗月師傅的公眾號看到了如何用使用Proxypool搭建代理池子。所以本篇部落格嘗試復現暗月師傅的技術,並且記錄其中的一些雷區。
原文連結:
https://mp.weixin.qq.com/s/Ow9MQAEgfg0FEM40ckItGw
正文
1.部署Redis資料庫
1.1安裝Redis
#1.下載穩定版本的redis
apt-get install redis-server
#2.啟用客戶端
redis-cli
1.2修改Redis配置檔案
#1.編輯配置檔案 vi /etc/redis/redis.conf #2.關閉保護模式 protected-mode no #3.取消守護程序 daemonsize no
1.3拉取Proxypool
docker pull jhao104/proxy_pool
docker run --env DB_CONN=redis://:@10.211.55.6:6379/0 -p 5010:5010jhao104/proxy_pool:latest
注意這裡如果是部署在伺服器上,上需要開放6379埠的。
執行成功結果:
2配置Proxifier
2.1生成配置檔案
使用Python生成配置檔案
# -*- coding:utf8 -*- import redis import json from xml.etree import ElementTree def RedisProxyGet(): ConnectString = [] pool = redis.ConnectionPool(host='10.211.55.6', 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: # JSON解析異常處理 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 # 從101開始增加 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 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 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配置檔案建立完成....")
`
生成的配置檔案雙擊即可倒入Proxifier
此時執行程式即可經過代理。