Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from ddgth:master #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 41 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
### 增加dddb/cf2dns docker镜像 --update 2024.6.4

> 使用方法

1. 拉取cf2dns docker镜像 `docker pull dddb/cf2dns`

2. 新建cf2dns_docker工作路径 `cd ~ && mkdir -p cf2dns_docker/logs && cd cf2dns_docker`

3. 下载所需配置文件 `wget --no-check-certificate -qO ./config.ini https://raw.githubusercontent.com/ddgth/cf2dns/master/docker/src/config.ini`

4. 根据注释修改`config.ini`配置文件

5. 运行docker镜像 `docker run -d -v ~/cf2dns_docker/config.ini:/cf2dns/src/config.ini -v ~/cf2dns_docker/logs:/cf2dns/logs dddb/cf2dns`

6. 查看运行日志 `tail -100f ~/cf2dns_docker/logs/cf2dns.log`



### 修复腾讯云 DNS 无法调用 --update 2023.1.3

[API 2.0下线通知](https://cloud.tencent.com/document/product/1278/82311) By github@z0z0r4

### 新增支持Actions自选更新V4或V6 ——update 2022.12.19

> 使用方法

1. 修改 **`.github/workflows/run.yml`**
1. 修改 **`.github/workflows/run.yml`**

2. 新增secret **`DOMAINSV6`**
### 新增支持华为云DNS ——update 2022.10.25
> 使用方法
2. 新增secret **`DOMAINSV6`**

### 新增支持华为云DNS ——update 2022.10.25

> 使用方法

1. 安装依赖 **`pip install -r requirements.txt`**
3. 安装依赖 **`pip install -r requirements.txt`**

2. 修改配置文件 **`DNS_SERVER`** **`SECRETID`** **`SECRETKEY`** **`REGION_HW`**
4. 修改配置文件 **`DNS_SERVER`** **`SECRETID`** **`SECRETKEY`** **`REGION_HW`**

### 新增优选IPv6功能 ——update 2022.07.06

> 使用方法

更新代码,修改脚本中的 `TYPE` 参数即可
更新代码,修改脚本中的 `TYPE` 参数即可

### 新增默认线路记录 ——update 2021.12.15

Expand All @@ -33,7 +56,7 @@

> 实现方式

之前不管您使用免费的key还是付费的key所筛选出来的Cloudflare IP都是多人共享的,如果其中有人的网站刚好被假墙,而您自选出来的IP刚好和他的相同,那么您的网站也有被假墙的风险,当然我也使用了各种手动去解决这个方法,比如增加接口返回IP数、随机获取优选IP等,但最总还是不能完全杜绝这情况的发现,所以现增加了一个优选IP池,只需在您的key后面加上 **`fgfw`** ,您就会每次执行脚本都能获取到**最新的独享优选IP**,由于这需要消耗更多的服务器硬件和带宽资源,那么每次调用获取最新的独享优选IP时,您只能获取到每个运营商的**2条**优选记录,并且每次调用您将消耗更多的key调用次数,执行频率建议与您DNS服务商的最小TTL保持一直(记得把脚本中的TTL参数也修改了)。
之前不管您使用免费的key还是付费的key所筛选出来的Cloudflare IP都是多人共享的,如果其中有人的网站刚好被假墙,而您自选出来的IP刚好和他的相同,那么您的网站也有被假墙的风险,当然我也使用了各种手动去解决这个方法,比如增加接口返回IP数、随机获取优选IP等,但最总还是不能完全杜绝这情况的发现,所以现增加了一个优选IP池,只需在您的key后面加上 **`fgfw`** ,您就会每次执行脚本都能获取到**最新的独享优选IP**,由于这需要消耗更多的服务器硬件和带宽资源,那么每次调用获取最新的独享优选IP时,您只能获取到每个运营商的**2条**优选记录,并且每次调用您将消耗更多的key调用次数,执行频率建议与您DNS服务商的最小TTL保持一直(记得把脚本中的TTL参数也修改了)。

> 使用方法:

Expand All @@ -48,7 +71,6 @@

**详细的使用场景请移步我的[小站](https://blog.hostmonit.com/cloudflare-select-ip-plus/)**


### 适用人群

1. 小站长,网站经常被打或网站放置在国外需要稳定且速度相对快的CDN
Expand All @@ -58,9 +80,9 @@
### 使用方法

> 必要条件:
>
>
> ★ Cloudflare自选IP并已接入到DNSPod或阿里云DNS,不知道怎么自选IP可以查看这个[教程](https://blog.hostmonit.com/manually-select-ip/)
>
>
> ★ Python3、pip环境

#### 方法一:在自己的VPS或电脑中运行(推荐)
Expand All @@ -85,42 +107,36 @@ pip install -r requirements.txt
python cf2dns.py
```



#### 方法二:GitHub Actions 运行

1. 登录[腾讯云后台](https://console.cloud.tencent.com/cam/capi)或者[阿里云后台](https://help.aliyun.com/document_detail/53045.html?spm=a2c4g.11186623.2.11.2c6a2fbdh13O53),获取 SecretId、SecretKey,如果使用阿里云DNS,注意需要添加DNS控制权限**AliyunDNSFullAccess**

2. Fork本项目到自己的仓库![fork.png](https://img.hostmonit.com/images/2020/11/05/fork.png)

3. 进入第二步中Fork的项目,点击Settings->Secrets and variables-> Actions -> New repository secret,分别是DOMAINS,KEY,SECRETID,SECRETKEY。

> - DOMAINS 需改域名信息,填写时注意不要有换行 例如:`{"hostmonit.com": {"@": ["CM","CU","CT"], "shop": ["CM", "CU", "CT"], "stock": ["CM","CU","CT"]},"4096.me": {"@": ["CM","CU","CT"], "vv":["CM","CU","CT"]}}`
> - DOMAINSV6 如果需要更新AAA解析请增加此secrets,格式同DOMAINS。
> - KEY API密钥,从[商店](https://shop.hostmonit.com)购买KEY,也可以使用这个KEY `o1zrmHAF` ,区别是 `o1zrmHAF` 是历史优选的Cloudflare IP(也可以从这个[网站](https://stock.hostmonit.com/CloudFlareYes)查到IP的信息),而购买的KEY是15分钟内获取到的对各运营商速度最优的的Cloudflare IP
> - SECRETID 第一部中从[腾讯云后台](https://console.cloud.tencent.com/cam/capi)或者[阿里云后台](https://help.aliyun.com/document_detail/53045.html?spm=a2c4g.11186623.2.11.2c6a2fbdh13O53),获取到的 `SECRETID `
> - SECRETKEY 第一部中从[腾讯云后台](https://console.cloud.tencent.com/cam/capi)或者[阿里云后台](https://help.aliyun.com/document_detail/53045.html?spm=a2c4g.11186623.2.11.2c6a2fbdh13O53),获取到的 `SECRETKEY`

![secret.png](https://img.hostmonit.com/images/2023/03/04/actions.png)

4. 修改您项目中的 `cf2dns_actions.py`文件中的`AFFECT_NUM`和`DNS_SERVER`参数,继续修改`.github/workflows/run.yml` 文件,定时执行的时长(建议15分钟执行一次),最后点击 `start commit` 提交即可在Actions中的build查看到执行情况,如果看到 `cf2dns` 执行日志中有 `CHANGE DNS SUCCESS` 详情输出,即表示运行成功。**需要注意观察下次定时是否能正确运行,有时候GitHub Actions 挺抽风的**

![modify.png](https://img.hostmonit.com/images/2020/11/05/modify.png)



![commit.png](https://img.hostmonit.com/images/2020/11/05/commit.png)



![build.png](https://img.hostmonit.com/images/2020/11/05/build.png)

### 免责声明

> 1.网络环境错综复杂,适合我的不一定适合你,所以尽量先尝试免费的KEY或者购买试用版的KEY
>
>
> 2.有什么问题和建议请提issue或者Email我,不接受谩骂、扯皮、吐槽
>
>
> 3.为什么收费? 这个标价我也根本不指望赚钱,甚至不够我国内一台VDS的钱。
>
>
> ★ 如果当前DNSPod有移动、联通、电信线路的解析将会覆盖掉

29 changes: 29 additions & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
**/__pycache__
**/*venv
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
*.db
.python-version
LICENSE
README.md
26 changes: 26 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# syntax=docker/dockerfile:1

FROM python:3.8-slim-buster

LABEL maintainer="[email protected]"

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

WORKDIR /cf2dns

COPY . /cf2dns

# Install pip requirements
RUN python -m pip install --no-cache-dir --upgrade -r requirements.txt



# Creates a non-root user with an explicit UID and adds permission to access the /app folder
#RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
#USER appuser

CMD ["python3", "src/main.py"]
15 changes: 15 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### 增加dddb/cf2dns docker镜像 --update 2024.6.4

> 使用方法

1. 拉取cf2dns docker镜像 `docker pull dddb/cf2dns`

2. 新建cf2dns_docker工作路径 `cd ~ && mkdir -p cf2dns_docker/logs && cd cf2dns_docker`

3. 下载所需配置文件 `wget --no-check-certificate -qO ./config.ini https://raw.githubusercontent.com/ddgth/cf2dns/master/docker/src/config.ini`

4. 根据注释修改`config.ini`配置文件

5. 运行docker镜像 `docker run -d -v ~/cf2dns_docker/config.ini:/cf2dns/src/config.ini -v ~/cf2dns_docker/logs:/cf2dns/logs dddb/cf2dns`

6. 查看运行日志 `tail -100f ~/cf2dns_docker/logs/cf2dns.log`
6 changes: 6 additions & 0 deletions docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
aliyun-python-sdk-alidns==2.6.19
aliyun-python-sdk-core==2.13.29
huaweicloudsdkcore==3.1.5
huaweicloudsdkdns==3.1.5
requests==2.28.1
tencentcloud-sdk-python==3.0.806
35 changes: 35 additions & 0 deletions docker/src/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[DEFAULT]
;也可以从https://shop.hostmonit.com获取
KEY = o1zrmHAF

;修改需要优选的域名、子域名和线路信息 示例表示要优选的域名有 hostxxnit.com, shop.hostxxnit.com stock.hostxxnit.com, 484848.xyz, shop.484848.xyz
;优选线路字典对照表 CM:移动 CU:联通 CT:电信 AB:境外 DEF:默认
DOMAINS = {"hostxxnit.com": {"@": ["CM","CU","CT"], "shop": ["CM", "CU", "CT"], "stock": ["CM","CU","CT"]},"484848.xyz": {"@": ["CM","CU","CT"], "shop": ["CM","CU","CT"]}}

;解析生效条数 免费版DNSPod相同线路最多支持2条解析
AFFECT_NUM = 2

;DNS服务商 DNSPod: 1, 阿里云: 2, 华为云: 3
DNS_SERVER = 1

;如果使用华为云解析 需要从API凭证-项目列表中获取 REGION
REGION_HW = cn-east-3

;如果使用阿里云解析 REGION出现错误再修改 默认不需要修改 https://help.aliyun.com/document_detail/198326.html
REGION_ALI = cn-hongkong

;解析生效时间,默认为600秒 如果不是DNS付费版用户 不要修改!!!
TTL = 600

;v4为筛选出IPv4的IP v6为筛选出IPv6的IP
TYPE = v4

;API 密钥
;腾讯云后台获取 https://console.cloud.tencent.com/cam/capi
;阿里云后台获取 https://help.aliyun.com/document_detail/53045.html?spm=a2c4g.11186623.2.11.2c6a2fbdh13O53 注意需要添加DNS控制权限 AliyunDNSFullAccess
;华为云后台获取 https://support.huaweicloud.com/devg-apisign/api-sign-provide-aksk.html
SECRETID = WTTCWxxxxxxxxxxxxxxxxxxxxx84O0V
SECRETKEY = GXkG6D4X1Nxxxxxxxxxxxxxxxxxxxxx4lRg6lT

;间隔多长时间执行一次 单位:秒
TIMES = 300
Empty file added docker/src/dns/__init__.py
Empty file.
89 changes: 89 additions & 0 deletions docker/src/dns/aliyun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Mail: [email protected]
# Reference: https://help.aliyun.com/document_detail/29776.html?spm=a2c4g.11186623.2.38.3fc33efexrOFkT
# REGION: https://help.aliyun.com/document_detail/198326.html
import json
from aliyunsdkcore import client
from aliyunsdkalidns.request.v20150109 import DescribeDomainRecordsRequest
from aliyunsdkalidns.request.v20150109 import DeleteDomainRecordRequest
from aliyunsdkalidns.request.v20150109 import UpdateDomainRecordRequest
from aliyunsdkalidns.request.v20150109 import AddDomainRecordRequest


rc_format = 'json'
class AliApi():
def __init__(self, ACCESSID, SECRETKEY, REGION='cn-hongkong'):
self.access_key_id = ACCESSID
self.access_key_secret = SECRETKEY
self.region = REGION

def del_record(self, domain, record):
clt = client.AcsClient(self.access_key_id, self.access_key_secret, self.region)
request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
request.set_RecordId(record)
request.set_accept_format(rc_format)
result = clt.do_action(request).decode('utf-8')
result = json.JSONDecoder().decode(result)
return result

def get_record(self, domain, length, sub_domain, record_type):
clt = client.AcsClient(self.access_key_id, self.access_key_secret, self.region)
request = DescribeDomainRecordsRequest.DescribeDomainRecordsRequest()
request.set_DomainName(domain)
request.set_PageSize(length)
request.set_RRKeyWord(sub_domain)
request.set_Type(record_type)
request.set_accept_format(rc_format)
result = clt.do_action(request).decode('utf-8').replace('DomainRecords', 'data', 1).replace('Record', 'records', 1).replace('RecordId', 'id').replace('Value', 'value').replace('Line', 'line').replace('telecom', '电信').replace('unicom', '联通').replace('mobile', '移动').replace('oversea', '境外').replace('default', '默认')
result = json.JSONDecoder().decode(result)
return result

def create_record(self, domain, sub_domain, value, record_type, line, ttl):
clt = client.AcsClient(self.access_key_id, self.access_key_secret, self.region)
request = AddDomainRecordRequest.AddDomainRecordRequest()
request.set_DomainName(domain)
request.set_RR(sub_domain)
if line == "电信":
line = "telecom"
elif line == "联通":
line = "unicom"
elif line == "移动":
line = "mobile"
elif line == "境外":
line = "oversea"
elif line == "默认":
line = "default"
request.set_Line(line)
request.set_Type(record_type)
request.set_Value(value)
request.set_TTL(ttl)
request.set_accept_format(rc_format)
result = clt.do_action(request).decode('utf-8')
result = json.JSONDecoder().decode(result)
return result

def change_record(self, domain, record_id, sub_domain, value, record_type, line, ttl):
clt = client.AcsClient(self.access_key_id, self.access_key_secret, self.region)
request = UpdateDomainRecordRequest.UpdateDomainRecordRequest()
request.set_RR(sub_domain)
request.set_RecordId(record_id)
if line == "电信":
line = "telecom"
elif line == "联通":
line = "unicom"
elif line == "移动":
line = "mobile"
elif line == "境外":
line = "oversea"
elif line == "默认":
line = "default"
request.set_Line(line)
request.set_Type(record_type)
request.set_Value(value)
request.set_TTL(ttl)
request.set_accept_format(rc_format)
result = clt.do_action(request).decode('utf-8')
result = json.JSONDecoder().decode(result)
return result

Loading