├── .github └── workflows │ ├── caijiip.yml │ └── main.yml ├── README.md ├── bestdomain.py ├── collect_ips.py └── ip.txt /.github/workflows/caijiip.yml: -------------------------------------------------------------------------------- 1 | name: Update IP List 2 | 3 | on: 4 | schedule: 5 | - cron: '*/30 * * * *' # 每隔三十分钟运行一次 6 | workflow_dispatch: # 手动触发 7 | # push: # 允许提交触发 8 | 9 | jobs: 10 | 11 | update-ip-list: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | 17 | - name: Set up Python 18 | uses: actions/setup-python@v4 19 | with: 20 | python-version: '3.9' 21 | 22 | - name: Install dependencies 23 | run: | 24 | python -m pip install --upgrade pip 25 | pip install requests 26 | pip install beautifulsoup4 27 | 28 | - name: Run script 29 | run: python ${{ github.workspace }}/collect_ips.py 30 | 31 | - name: Commit and push changes 32 | run: | 33 | git config --global user.email "baolw50@gmail.com" 34 | git config --global user.name "jc-lw" 35 | if [ -n "$(git status --porcelain)" ]; then 36 | git add ip.txt 37 | git commit -m "Automatic update" 38 | git push 39 | else 40 | echo "No changes detected, skipping commit." 41 | fi 42 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Update Cloudflare DNS 2 | 3 | on: 4 | schedule: 5 | - cron: '*/30 * * * *' # 每隔三十分钟运行一次 6 | workflow_dispatch: # 手动触发 7 | # push: # 允许提交触发 8 | 9 | jobs: 10 | update-dns: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Checkout repository 15 | uses: actions/checkout@v4 16 | 17 | - name: Set up Python 18 | uses: actions/setup-python@v4 19 | with: 20 | python-version: '3.x' # 你可以指定需要的 Python 版本 21 | 22 | - name: Install dependencies 23 | run: | 24 | python -m pip install --upgrade pip 25 | pip install requests 26 | 27 | - name: Run update script 28 | env: 29 | CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }} 30 | run: | 31 | python bestdomain.py 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # github项目 2 | - 原github作者[ tianshipapa ](https://github.com/tianshipapa)和 3 | [ymyuuu ](https://github.com/ymyuuu/BestDomain) 4 | - 老王只是合并两个项目 5 | - github项目地址 6 | ## 优选域名 , IP 取决于抓取的 网站 7 | - bestcf.cfcs.us.kg 8 | - api.cfcs.us.kg 9 | 10 | ![image.png](https://img.lwxpz.me/file/1736315762020_image.png) 11 | 12 | https://github.com/jc-lw/youxuanyuming 13 | 14 | ![image.png](https://img.kjzl.me/images/18b0be4bca205491b1aaf70983319fe504bef426.png) 15 | 16 | 17 | 18 | 19 | # cfipcaiji 原理和需要修改的地方 20 | 21 | - 每3小时自动抓取 https://ip.164746.xyz 的优选ip,形成ip.txt 22 | - 还有js自动生成的https://cf.090227.xyz 23 | ![image.png](https://img.kjzl.me/images/51e6dd9bbb99f98d3241509b804d98a4fc1fa5db.png) 24 | 25 | - `caijiip.yml `文件夹里面改成你自己的,否则报错 26 | ![image.png](https://img.kjzl.me/images/0ddaaecae1242f12aadaa847662d56a23398cda5.png) 27 | - `collect_ips.py`文件 这里是抓取优选IP的网站,如需要可自行修改 28 | ![image.png](https://img.kjzl.me/images/38a3d57288da468b17964664e54da54a4175ba0e.png) 29 | 30 | # BestDomain 需要Cloudflare API令牌 31 | 32 | - 这里修改你的二级域名开头 33 | ![image.png](https://img.kjzl.me/images/85362a2f5680355d4d73a2293ce82099c42e3308.png) 34 | ![image.png](https://img.kjzl.me/images/5def5f757d7a63978358e5a950714bed3dc6c213.png) 35 | - 把上面的链接 修改成 你自己的链接,因为你抓取优选ip可能跟我不一样。 36 | ![image.png](https://img.kjzl.me/images/52f07d0b88279fb13694e1071d3184082408cf3d.png) 37 | 38 | 39 | 40 | 1. 创建 Cloudflare API 令牌 41 | 访问 [Cloudflare API Tokens](https://dash.cloudflare.com/profile/api-tokens) 42 | 43 | 2. 选择需要解析的域名,创建编辑 DNS 权限的` CF_API_TOKEN` 44 | ![image.png](https://img.kjzl.me/images/35feefcde1ed0cc08e430e419de73b892157d35c.png) 45 | 46 | 47 | 3. 在你的 GitHub 仓库中,设置 `CF_API_TOKEN `为你的 Cloudflare API 令牌 48 | ![image.png](https://img.kjzl.me/images/004eb6d2c8441cfa266129b3906e43e60bf99090.png) 49 | 50 | 51 | 4. 配置 GitHub Actions 定时任务 52 | - 编辑 [.github/workflows/main.yml](.github/workflows/main.yml) 文件,设置 `cron` 表达式以定义任务运行时间 53 | "# youxuanyuming" 54 | 55 | # 设置完成 56 | ![image.png](https://img.kjzl.me/images/defa31617244ae82e89f05480be397eb3938f15e.png) 57 | 这里就是 运行完成,去ping出来的优选IP 58 | ![image.png](https://img.kjzl.me/images/8816d5204054629815ecf6add95e9e244849e85b.png) 59 | 60 | 61 | # 开源协议 62 | 欢迎使用、修改和传播这个脚本!如果你觉得它对你有帮助,记得来点个 Star ⭐ 哦~ 63 | 64 | - 💡 免责声明: 本脚本由作者热爱 Linux 的灵魂驱动编写,虽尽力确保安全,但任何使用问题请自负风险! 65 | 66 | 赞助声明 67 | 本项目由 VTEXS 的「开源项目免费 VPS 计划」提供算力支持。 68 | 感谢 VTEXS 对开源社区的支持! 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /bestdomain.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | def get_ip_list(url): 5 | response = requests.get(url) 6 | response.raise_for_status() 7 | return response.text.strip().split('\n') 8 | 9 | def get_cloudflare_zone(api_token): 10 | headers = { 11 | 'Authorization': f'Bearer {api_token}', 12 | 'Content-Type': 'application/json', 13 | } 14 | response = requests.get('https://api.cloudflare.com/client/v4/zones', headers=headers) 15 | response.raise_for_status() 16 | zones = response.json().get('result', []) 17 | if not zones: 18 | raise Exception("No zones found") 19 | return zones[0]['id'], zones[0]['name'] 20 | 21 | def delete_existing_dns_records(api_token, zone_id, subdomain, domain): 22 | headers = { 23 | 'Authorization': f'Bearer {api_token}', 24 | 'Content-Type': 'application/json', 25 | } 26 | record_name = domain if subdomain == '@' else f'{subdomain}.{domain}' 27 | while True: 28 | response = requests.get(f'https://api.cloudflare.com/client/v4/zones/{zone_id}/dns_records?type=A&name={record_name}', headers=headers) 29 | response.raise_for_status() 30 | records = response.json().get('result', []) 31 | if not records: 32 | break 33 | for record in records: 34 | delete_response = requests.delete(f'https://api.cloudflare.com/client/v4/zones/{zone_id}/dns_records/{record["id"]}', headers=headers) 35 | delete_response.raise_for_status() 36 | print(f"Del {subdomain}:{record['id']}") 37 | 38 | def update_cloudflare_dns(ip_list, api_token, zone_id, subdomain, domain): 39 | headers = { 40 | 'Authorization': f'Bearer {api_token}', 41 | 'Content-Type': 'application/json', 42 | } 43 | record_name = domain if subdomain == '@' else f'{subdomain}.{domain}' 44 | for ip in ip_list: 45 | data = { 46 | "type": "A", 47 | "name": record_name, 48 | "content": ip, 49 | "ttl": 1, 50 | "proxied": False 51 | } 52 | response = requests.post(f'https://api.cloudflare.com/client/v4/zones/{zone_id}/dns_records', json=data, headers=headers) 53 | if response.status_code == 200: 54 | print(f"Add {subdomain}:{ip}") 55 | else: 56 | print(f"Failed to add A record for IP {ip} to subdomain {subdomain}: {response.status_code} {response.text}") 57 | 58 | if __name__ == "__main__": 59 | api_token = os.getenv('CF_API_TOKEN') 60 | 61 | # 示例URL和子域名对应的IP列表 62 | subdomain_ip_mapping = { 63 | 'bestcf': 'https://ipdb.030101.xyz/api/bestcf.txt', # #域名一,bestcf.域名.com 64 | 'api': 'https://raw.githubusercontent.com/jc-lw/youxuanyuming/refs/heads/main/ip.txt', #域名二,api.域名.com 65 | # 添加更多子域名和对应的IP列表URL 66 | } 67 | 68 | try: 69 | # 获取Cloudflare域区ID和域名 70 | zone_id, domain = get_cloudflare_zone(api_token) 71 | 72 | for subdomain, url in subdomain_ip_mapping.items(): 73 | # 获取IP列表 74 | ip_list = get_ip_list(url) 75 | # 删除现有的DNS记录 76 | delete_existing_dns_records(api_token, zone_id, subdomain, domain) 77 | # 更新Cloudflare DNS记录 78 | update_cloudflare_dns(ip_list, api_token, zone_id, subdomain, domain) 79 | 80 | except Exception as e: 81 | print(f"Error: {e}") 82 | -------------------------------------------------------------------------------- /collect_ips.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | import re 4 | import os 5 | 6 | # 目标URL列表 7 | urls = ['https://ip.164746.xyz/ipTop10.html', 8 | 'https://cf.090227.xyz' 9 | ] 10 | 11 | # 正则表达式用于匹配IP地址 12 | ip_pattern = r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' 13 | 14 | # 检查ip.txt文件是否存在,如果存在则删除它 15 | if os.path.exists('ip.txt'): 16 | os.remove('ip.txt') 17 | 18 | # 创建一个文件来存储IP地址 19 | with open('ip.txt', 'w') as file: 20 | for url in urls: 21 | # 发送HTTP请求获取网页内容 22 | response = requests.get(url) 23 | 24 | # 使用BeautifulSoup解析HTML 25 | soup = BeautifulSoup(response.text, 'html.parser') 26 | 27 | # 根据网站的不同结构找到包含IP地址的元素 28 | if url == 'https://ip.164746.xyz/ipTop10.html': 29 | elements = soup.find_all('tr') 30 | elif url == 'https://cf.090227.xyz': 31 | elements = soup.find_all('tr') 32 | else: 33 | elements = soup.find_all('li') 34 | 35 | # 遍历所有元素,查找IP地址 36 | for element in elements: 37 | element_text = element.get_text() 38 | ip_matches = re.findall(ip_pattern, element_text) 39 | 40 | # 如果找到IP地址,则写入文件 41 | for ip in ip_matches: 42 | file.write(ip + '\n') 43 | 44 | print('IP地址已保存到ip.txt文件中。') 45 | -------------------------------------------------------------------------------- /ip.txt: -------------------------------------------------------------------------------- 1 | 162.159.153.144 2 | 162.159.152.811 3 | 162.159.153.212 4 | 162.159.152.111 5 | 162.159.153.217 6 | 162.159.153.216 7 | 162.159.152.531 8 | 162.159.152.205 9 | 162.159.153.209 10 | 162.159.153.421 11 | 162.159.152.311 12 | 162.159.153.239 13 | 162.159.153.184 14 | 162.159.153.194 15 | 162.159.152.155 16 | 162.159.152.225 17 | 162.159.153.156 18 | 162.159.152.691 19 | 162.159.153.721 20 | 162.159.153.170 21 | 104.18.83.922 22 | 104.19.148.108 23 | 104.18.147.201 24 | 104.19.150.163 25 | 104.18.94.107 26 | 104.17.102.952 27 | 104.16.246.132 28 | 104.17.219.208 29 | 104.16.249.174 30 | 104.18.82.552 31 | 104.17.189.171 32 | 104.19.150.282 33 | 104.16.249.115 34 | 198.41.208.232 35 | 104.17.110.702 36 | 104.19.144.212 37 | 104.17.215.102 38 | 104.16.253.832 39 | 104.18.85.292 40 | 104.18.80.243 41 | 104.18.86.131 42 | 104.18.94.238 43 | 104.16.246.188 44 | 104.17.210.171 45 | 104.16.246.173 46 | 104.17.100.185 47 | 104.16.242.722 48 | 104.17.101.175 49 | 104.17.104.243 50 | 104.18.93.729 51 | 104.17.223.372 52 | 104.19.145.142 53 | 104.19.150.263 54 | 104.18.88.238 55 | 104.17.221.181 56 | 104.16.249.246 57 | 104.19.148.225 58 | 104.18.167.191 59 | 104.17.100.383 60 | 104.18.83.150 61 | 104.16.248.191 62 | 104.19.146.252 63 | 104.18.91.196 64 | 104.17.209.663 65 | 104.17.106.219 66 | 104.17.220.251 67 | 104.17.170.044 68 | 104.17.180.934 69 | 104.17.171.176 70 | 104.17.160.604 71 | 104.17.162.484 72 | 104.17.161.484 73 | 104.17.162.414 74 | 104.17.179.233 75 | 104.17.182.210 76 | 104.19.153.126 77 | 104.19.158.415 78 | 104.19.156.135 79 | 104.17.217.237 80 | 104.18.82.486 81 | 104.18.88.636 82 | 104.16.248.586 83 | 104.18.92.135 84 | 104.18.86.199 85 | 104.18.92.141 86 | 104.16.243.626 87 | 104.19.149.161 88 | 104.16.246.248 89 | 104.16.241.185 90 | 104.18.85.134 91 | 104.19.219.222 92 | 104.16.244.253 93 | 104.16.243.526 94 | 104.19.145.136 95 | 104.18.88.239 96 | 104.16.254.211 97 | 104.18.84.220 98 | 104.18.144.104 99 | 104.19.145.140 100 | 104.18.81.376 101 | 104.16.253.596 102 | 104.16.254.756 103 | 104.19.145.209 104 | 104.17.187.148 105 | 104.17.187.180 106 | 104.19.150.168 107 | 104.18.93.249 108 | 104.19.148.966 109 | 104.18.85.316 110 | 104.19.147.236 111 | 104.16.240.576 112 | 104.19.148.224 113 | 104.19.150.100 114 | 104.17.190.161 115 | 104.18.93.252 116 | 104.19.146.657 117 | 104.18.92.677 118 | 104.16.240.597 119 | 104.18.94.183 120 | 104.16.251.154 121 | 104.16.252.131 122 | 104.18.84.817 123 | 104.16.248.114 124 | 198.41.208.537 125 | 104.17.213.211 126 | 104.19.148.101 127 | 104.18.92.127 128 | 104.18.82.317 129 | 104.17.216.185 130 | 104.17.208.177 131 | 104.19.145.817 132 | 104.17.212.337 133 | 104.17.104.157 134 | 104.17.179.114 135 | 104.17.166.105 136 | 104.17.175.167 137 | 104.17.165.607 138 | 104.19.148.100 139 | 104.17.161.236 140 | 104.17.167.447 141 | 104.17.165.192 142 | 104.17.186.877 143 | 104.19.158.170 144 | 104.17.176.195 145 | 104.17.160.111 146 | 104.17.171.122 147 | 104.17.166.347 148 | 104.17.178.206 149 | 104.17.160.190 150 | 104.17.166.368 151 | 104.17.175.208 152 | 104.19.153.578 153 | 104.17.165.125 154 | 104.19.158.184 155 | 104.17.177.245 156 | 104.17.177.127 157 | 104.19.155.348 158 | 104.19.157.175 159 | 104.19.151.133 160 | 104.19.151.144 161 | 198.41.212.129 162 | 198.41.212.130 163 | 198.41.212.739 164 | 104.18.92.119 165 | 104.16.246.121 166 | 104.18.85.279 167 | 104.17.211.196 168 | 104.19.150.213 169 | 104.19.159.102 170 | 104.18.91.111 171 | 104.18.85.212 172 | 104.17.216.233 173 | 104.17.189.155 174 | 104.19.145.207 175 | 104.19.147.110 176 | 104.17.209.310 177 | 104.16.251.164 178 | 104.17.212.881 179 | 104.19.146.481 180 | 104.17.216.191 181 | 104.16.240.471 182 | 104.16.249.207 183 | 104.18.82.101 184 | 104.18.94.241 185 | 104.17.209.164 186 | 104.16.246.147 187 | 104.17.211.341 188 | 104.16.243.184 189 | 104.19.147.114 190 | 198.41.208.741 191 | 104.17.166.971 192 | 104.19.146.671 193 | 104.19.145.112 194 | 104.17.208.248 195 | 104.17.111.491 196 | 104.16.251.157 197 | 104.16.250.228 198 | 104.17.104.531 199 | 104.19.146.130 200 | 104.18.86.198 201 | 104.18.85.261 202 | 104.17.181.951 203 | 104.18.83.218 204 | 104.17.185.361 205 | 104.17.100.133 206 | 198.41.209.139 207 | 104.19.150.165 208 | 104.18.81.170 209 | 104.17.181.941 210 | 104.17.163.212 211 | 104.16.243.154 212 | 104.18.92.119 213 | 104.18.93.247 214 | 104.16.253.241 215 | 104.19.144.139 216 | 104.16.243.130 217 | 104.17.107.131 218 | 104.19.219.206 219 | 104.17.162.421 220 | 104.18.89.311 221 | 104.19.147.104 222 | 104.17.162.223 223 | 104.17.189.911 224 | 104.17.182.911 225 | 104.17.107.139 226 | 104.17.177.541 227 | 104.16.241.212 228 | 104.17.161.107 229 | 104.17.184.211 230 | 104.19.154.162 231 | 104.19.144.146 232 | 104.17.186.671 233 | 104.17.168.152 234 | 104.17.161.176 235 | 104.17.173.157 236 | 104.17.165.127 237 | 104.17.173.145 238 | 104.17.166.351 239 | 104.16.251.141 240 | 104.19.221.246 241 | 104.17.174.133 242 | 104.17.167.251 243 | 104.17.165.121 244 | 104.17.183.146 245 | 104.19.152.127 246 | 104.17.210.331 247 | 104.17.180.237 248 | 104.17.161.228 249 | 104.17.183.731 250 | 104.17.160.175 251 | 104.19.156.113 252 | 104.17.171.121 253 | 104.19.153.177 254 | 104.19.156.791 255 | 104.19.158.512 256 | 104.17.175.216 257 | 104.19.158.212 258 | 104.18.176.251 259 | 104.19.152.112 260 | 198.41.212.541 261 | 198.41.208.158 262 | 104.19.145.136 263 | 104.17.187.371 264 | 104.16.241.213 265 | 104.18.89.228 266 | 104.18.88.521 267 | 104.19.146.614 268 | 104.17.173.146 269 | 104.16.240.351 270 | 104.17.218.231 271 | 104.16.246.101 272 | 104.17.185.251 273 | 104.18.91.751 274 | 104.17.106.401 275 | 104.17.101.154 276 | 104.16.241.211 277 | 104.17.107.621 278 | 104.18.94.108 279 | 104.18.95.221 280 | 104.18.90.162 281 | 104.17.176.711 282 | 104.17.210.247 283 | 104.17.101.169 284 | 104.17.174.681 285 | 104.19.147.671 286 | 104.17.164.192 287 | 104.19.158.226 288 | 104.19.221.199 289 | 104.19.148.228 290 | 104.16.254.199 291 | 104.17.110.108 292 | 104.17.177.701 293 | 104.16.243.371 294 | 104.19.155.208 295 | 104.17.109.761 296 | 104.17.173.212 297 | --------------------------------------------------------------------------------