From 390dd0543e1167f031bfdcf825d84f2391b95555 Mon Sep 17 00:00:00 2001 From: NN708 Date: Wed, 6 Nov 2019 15:15:18 +0800 Subject: [PATCH 1/6] Update schema for HE.net --- schema.json | 5 +++-- schema/v2.json | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/schema.json b/schema.json index 5cb10ca..79b1b87 100644 --- a/schema.json +++ b/schema.json @@ -29,7 +29,7 @@ "$id": "/properties/dns", "type": "string", "title": "DNS Provider", - "description": "dns服务商:阿里为alidns,DNS.COM为dnscom,DNSPOD国际版为(dnspod_com),cloudflare", + "description": "dns服务商:阿里为alidns,DNS.COM为dnscom,DNSPOD国际版为(dnspod_com),cloudflare,HE.net为he", "default": "dnspod", "examples": [ "dnspod", @@ -41,7 +41,8 @@ "alidns", "cloudflare", "dnspod_com", - "dnscom" + "dnscom", + "he" ] }, "ipv4": { diff --git a/schema/v2.json b/schema/v2.json index 644af91..76a7014 100644 --- a/schema/v2.json +++ b/schema/v2.json @@ -31,10 +31,10 @@ "$id": "/properties/dns", "type": "string", "title": "DNS Provider", - "description": "dns服务商:阿里为alidns,DNS.COM为dnscom,DNSPOD国际版为dnspod_com,cloudflare", + "description": "dns服务商:阿里为alidns,DNS.COM为dnscom,DNSPOD国际版为dnspod_com,cloudflare,HE.net为he", "default": "dnspod", "examples": ["dnspod", "alidns", "cloudflare"], - "enum": ["dnspod", "alidns", "cloudflare", "dnspod_com", "dnscom"] + "enum": ["dnspod", "alidns", "cloudflare", "dnspod_com", "dnscom", "he"] }, "ipv4": { "$id": "/properties/ipv4", From 4cebf94114830bd06da48fd46d1486d60cc9a87a Mon Sep 17 00:00:00 2001 From: NN708 Date: Wed, 6 Nov 2019 15:52:26 +0800 Subject: [PATCH 2/6] Add he.py --- dns/he.py | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 dns/he.py diff --git a/dns/he.py b/dns/he.py new file mode 100644 index 0000000..605a173 --- /dev/null +++ b/dns/he.py @@ -0,0 +1,85 @@ +# coding=utf-8 +""" +Hurricane Electric (he.net) API +Hurricane Electric (he.net) 接口解析操作库 +https://dns.he.net/docs.html +@author: NN708 +""" + +from logging import debug, info, warning + +try: + # python 2 + from httplib import HTTPSConnection + from urllib import urlencode +except ImportError: + # python 3 + from http.client import HTTPSConnection + from urllib.parse import urlencode + +__author__ = 'NN708' + + +class Config: + TOKEN = "password" + PROXY = None # 代理设置 + + +class API: + # API 配置 + SITE = "dyn.dns.he.net" + METHOD = "POST" + ACTION = "nic/update" + TOKEN_PARAM = "password" # key name of token param + + +def request(param=None, **params): + """ + 发送请求数据 + """ + if param: + params.update(param) + + params.update({API.TOKEN_PARAM: '***'}) + info("%s/%s : %s", API.SITE, API.ACTION, params) + params[API.TOKEN_PARAM] = Config.TOKEN + + if Config.PROXY: + conn = HTTPSConnection(Config.PROXY) + conn.set_tunnel(API.SITE, 443) + else: + conn = HTTPSConnection(API.SITE) + + conn.request(API.METHOD, '/' + API.ACTION, urlencode(params), { + "Content-type": "application/x-www-form-urlencoded" + }) + response = conn.getresponse() + res = response.read().decode('utf8') + conn.close() + + if response.status < 200 or response.status >= 300: + warning('%s : error[%d]:%s', API.ACTION, response.status, res) + raise Exception(res) + else: + debug('%s : result:%s', API.ACTION, res) + if not res: + raise Exception("empty response") + elif res == "nochg" or res == "good": # No change or success + return res + else: + raise Exception(res) + + +def update_record(domain, value, record_type="A"): + """ + 更新记录 + """ + info(">>>>>%s(%s)", domain, record_type) + res = request(hostname=domain, myip=value) + if res == "good": + result = "Record updated. New IP is: " + value + elif res == "nochg": + result = "IP not changed." + else: + result = "Record update failed." + return result From 2ed50db0681ba902e444425d37143df57b273f0a Mon Sep 17 00:00:00 2001 From: NN708 Date: Wed, 6 Nov 2019 15:58:33 +0800 Subject: [PATCH 3/6] Fix success judge --- dns/he.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dns/he.py b/dns/he.py index 605a173..ea4b12c 100644 --- a/dns/he.py +++ b/dns/he.py @@ -64,7 +64,7 @@ def request(param=None, **params): debug('%s : result:%s', API.ACTION, res) if not res: raise Exception("empty response") - elif res == "nochg" or res == "good": # No change or success + elif res[:5] == "nochg" or res[:4] == "good": # No change or success return res else: raise Exception(res) @@ -76,10 +76,10 @@ def update_record(domain, value, record_type="A"): """ info(">>>>>%s(%s)", domain, record_type) res = request(hostname=domain, myip=value) - if res == "good": - result = "Record updated. New IP is: " + value - elif res == "nochg": - result = "IP not changed." + if res[:4] == "good": + result = "Record updated. New IP is: " + res[5:-1] + elif res[:5] == "nochg": + result = "IP not changed. IP is: " + res[6:-1] else: result = "Record update failed." return result From b651791d8db34fbde067ec2b460583fbee9776bc Mon Sep 17 00:00:00 2001 From: NN708 Date: Wed, 6 Nov 2019 16:01:38 +0800 Subject: [PATCH 4/6] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5a18682..3bbbe60 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ - [x] [DNS.COM](https://www.dns.com/)(@loftor-git) - [x] [DNSPOD 国际版](https://www.dnspod.com/) - [x] [CloudFlare](https://www.cloudflare.com/)(@tongyifan) + - [x] [HE.net](https://dns.he.net/)(@NN708) - 其他: - [x] 可设置定时任务 - [x] 本地文件缓存(减少 API 请求) @@ -102,9 +103,9 @@ python run.py -c /path/to/config.json | key | type | required | default | description | tips | | :----: | :---------: | :------: | :---------: | :--------------: | ----------------------------------------------------------------- | -| id | string | √ | 无 | api 访问 ID | cloudflare 为邮箱 | +| id | string | √ | 无 | api 访问 ID | cloudflare 为邮箱,
HE.net 可留空 | | token | string | √ | 无 | api 授权 token | 也叫 secret key, **反馈粘贴时删除** | -| dns | string | No | `"dnspod"` | dns 服务商 | 阿里`alidns`,
dns.com 为`dnscom`,
DNSPOD 国际版`dnspod_com` | +| dns | string | No | `"dnspod"` | dns 服务商 | 阿里`alidns`,
dns.com 为`dnscom`,
DNSPOD 国际版`dnspod_com`,
HE.net 为`he` | | ipv4 | array | No | `[]` | ipv4 域名列表 | 为`[]`时,不会获取和更新 IPv4 地址 | | ipv6 | array | No | `[]` | ipv6 域名列表 | 为`[]`时,不会获取和更新 IPv6 地址 | | index4 | string\|int | No | `"default"` | ipv4 获取方式 | 可设置`网卡`,`内网`,`公网`,`正则`等方式 | @@ -133,7 +134,7 @@ python run.py -c /path/to/config.json "$schema": "https://ddns.newfuture.cc/schema/v2.json", "id": "12345", "token": "mytokenkey", - "dns": "dnspod 或 dnspod_com 或 alidns 或 dnscom 或 cloudflare", + "dns": "dnspod 或 dnspod_com 或 alidns 或 dnscom 或 cloudflare 或 he", "ipv4": ["ddns.newfuture.cc", "ipv4.ddns.newfuture.cc"], "ipv6": ["ddns.newfuture.cc", "ipv6.ddns.newfuture.cc"], "index4": 0, From c6c72cb09275bd4a73473d3c5d0291f5b745627e Mon Sep 17 00:00:00 2001 From: NN708 Date: Wed, 6 Nov 2019 16:05:22 +0800 Subject: [PATCH 5/6] Add document URL --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3bbbe60..fa3519a 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ - [DNS.COM API Key/Secret](https://www.dns.com/member/apiSet) - [DNSPOD(国际版)](https://www.dnspod.com/docs/info.html#get-the-user-token) - [CloudFlare API Key](https://support.cloudflare.com/hc/en-us/articles/200167836-Where-do-I-find-my-Cloudflare-API-key-) + - [HE.net DDNS 文档](https://dns.he.net/docs.html)(仅需将设置的密码填入`token`字段,`id`字段可留空) 2. 修改配置文件,`ipv4`和`ipv6`字段,为待更新的域名,详细参照配置说明 From 319bed1cb9ce7eb52192249d7c93d8116dad1a74 Mon Sep 17 00:00:00 2001 From: NN708 Date: Wed, 6 Nov 2019 22:13:43 +0800 Subject: [PATCH 6/6] Add notice for no record auto-creating --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fa3519a..e838872 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ - [x] [DNS.COM](https://www.dns.com/)(@loftor-git) - [x] [DNSPOD 国际版](https://www.dnspod.com/) - [x] [CloudFlare](https://www.cloudflare.com/)(@tongyifan) - - [x] [HE.net](https://dns.he.net/)(@NN708) + - [x] [HE.net](https://dns.he.net/)(@NN708) (不支持自动创建记录) - 其他: - [x] 可设置定时任务 - [x] 本地文件缓存(减少 API 请求)