Giter Club home page Giter Club logo

aliyun-ddns-client's Introduction

aliyun-ddns-client(v0.3)

Python DDNS client for Aliyun(http://www.hdget.com/aliyun-ddns-client)

LIMITATION

This version of DDNS client only supports auto updating 'A' type DomainRecord with IPV4 address.

Other types are not supported because they need following value format other than IP address:

  • 'NS', 'MX', 'CNAME' types DomainRecord need domain name format value
  • 'AAAA' type DomainRecord need IPV6 address format value
  • 'SRV' type DomainRecord need name.protocal format value
  • 'Explicit URL' and 'Implicit URL' need URL format value

PREREQUISITE

Some 3rd party python libraries are required for aliyun-ddns-client as below, you can install it via pip or easy_install:

  • requests
  • netifaces (needed only when you want to get IP address from the interface setting, it maybe useful when you have multiple interfaces.)

For example:

# pip install requests
# pip install netifaces # optional 

INSTALLATION

1. USE CRONJOB

  1. Download all files to somewhere, e,g: /opt/aliyun-ddns-client
  2. Rename "ddns.conf.example" to "ddns.conf" in the same dir
  3. Create a cronjob which execute "python ddns.py" periodly, e,g: */5 * * * * cd /opt/aliyun-ddns-client && /usr/bin/python ddns.py
  4. Make sure ddns.conf can be accessed by cronjob user

2. USE SYSTEMD

  1. Download all files to some where, e,g:/root/tools/aliyun-ddns-client
  2. Rename "ddns.conf.example" to "ddns.conf" in the same dir
  3. Copy two files: "ddns.timer" and "ddns.service" to "/usr/lib/systemd/system"
 root@local# systemctl daemon-reload
 root@local# systemctl start ddns.timer
 root@local# systemctl status ddns.timer -l

CONFIGURATION

Required options need to be set in /etc/ddns.conf:

  • access_id
  • access_key
  • domain
  • sub_domain

Optional options:

  • type
  • debug
[DEFAULT]
# access id obtains from aliyun
access_id=
# access key obtains from aliyun
access_key=
# it is not used at this moment, you can just ignore it
interval=600
# turn on debug mode or not
debug=true

[DomainRecord1]
# domain name, like google.com
domain=
# subdomain name, like www, blog, bbs, *, @, ...
sub_domain=
# resolve type, 'A', 'AAAA'..., currently it only supports 'A'
type=A

[feature_public_ip_from_nic]
enable=false
interface=eth0

GETTING STARTED

  1. Create a DNS resolve entry in Aliyun console manually, e,g: blog.guanxigo.com
  2. You can leave any IP address on Aliyun server for this entry, like 192.168.0.1
  3. Make sure all required options are inputted correctly in "ddns.conf"
  4. Enable the features you want to use.
  5. Make sure "ddns.conf" can be readable for the user who setup cron job

NOTICE: Only domain records both defined in local config file and Aliyun server will be updated

FAQ

  • Q: Why it failed with error message "The input parameter "Timestamp" that is mandatory for processing this request is not supplied." in describeDomainRecords()?

    A: Please check what's the value in params 'TimeStamp'. If the value has big difference with the correct time, you need use ntpdate to sync system time to the correct one.

  • Q: Why it failed with error message "Failed to save the config value"?

    A: You need make sure current cronjob user has permission to write file /etc/ddns.conf.

  • Q: Why it raise exception "AttributeError: 'X509' object has no attribute '_x509'"?

    A: PyOpenSSL version need >= 0.14, and you may try to fix this problem by do following:

    sudo yum uninstall python-requests
    sudo pip uninstall pyopenssl cryptography requests
    sudo pip install requests
    

aliyun-ddns-client's People

Contributors

cutesakurahime avatar kenpachi123 avatar rfancn avatar yuguorui avatar zcq100 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aliyun-ddns-client's Issues

update yunresolver.py

def get_common_params(self):
"""
Build common params which need invoke Aliyun API
:return: dict of all nessary params
"""
# ISO8601 standard: YYYY-MM-DDThh:mm:ssZ, e,g:2015-0109T12:00:00Z (UTC Timezone)
current_timestamp = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
signature_nonce = uuid.uuid4()

    common_params = {
        'Format': 'json',
        'Version': '2015-01-09',
        'AccessKeyId': self.access_id,
        'Timestamp': current_timestamp,
        'SignatureMethod': 'HMAC-SHA1',
        'SignatureNonce': signature_nonce,
        'SignatureVersion': "1.0",
    }

外网IP地址更改后,无法更新IP

2016-12-27 12:22:45 [ERROR] Failed to fetch remote DomainRecords.
2016-12-27 12:22:45 [ERROR] Failed finding remote DomainRecord[@.xxx.com]

家里断电,路由器和电脑关掉。来电后,IP地址更改出错

ImportError: No module named requests

Run after the emergence of

Traceback (most recent call last):
File "ddns.py", line 21, in
from helper import DDNSHelper
File "/opt/aliyun-ddns-client/helper.py", line 20, in
from utils import DDNSUtils
File "/opt/aliyun-ddns-client/utils.py", line 20, in
import requests
ImportError: No module named requests

subdomain不是精确匹配的问题

如果多个域名有重叠部分,比如pi和rpi,提示:
[ERROR] Duplicate DomainRecord in Aliyun
如下function,需要额外处理下:
self.resolver.describe_domain_records

运用systemd的Timer文件定时运行ddns.py

首先要有一个服务,可以起名ddns.service,内容如下:
[Unit]
Description=Aliyun DDNS Client.
Wants=network-online.target
After=network.target network-online.target

[Service]
Type=simple
WorkingDirectory=/root/tools/aliyun-ddns-client
#这里写上你的aliyun-ddns-client文件夹地址,如果用我的范例请放入/root文件夹下
ExecStart=/usr/bin/python ddns.py

然后有个同名的Timer文件,ddns.timer,内容如下:
[Unit]
Description=Run Aliyun DDNS Client every 10 minutes.

[Timer]
OnBootSec=0s
OnUnitActiveSec=10min
#这里可以改成你喜欢的时间
Unit=ddns.service
#默认不写Unit时Timer文件运行同名Service,可以省略

[Install]
WantedBy=multi-user.target

两个文件同时放入/usr/lib/systemd/system文件夹中,然后运行命令
#systemctl daemon-reload
#systemctl enable ddns.timer
可以查看状态:
#systemctl status ddns.timer

ImportError: No module named requests

已经安装了requests和netifaces,为什么运行python ddns.py还提示错误。

snowdream$ cd /Users/snowdream/bin/aliyun-ddns-client && /usr/bin/python ddns.py
Traceback (most recent call last):
 File "ddns.py", line 20, in <module>
   from utils import DDNSUtils
 File "/Users/snowdream/bin/aliyun-ddns-client/utils.py", line 26, in <module>
   import requests
ImportError: No module named requests
snowdream$ pip install requests
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: requests in /usr/local/lib/python3.6/site-packages (2.18.4)
Requirement already satisfied: idna<2.7,>=2.5 in /usr/local/lib/python3.6/site-packages (from requests) (2.6)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/site-packages (from requests) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/site-packages (from requests) (2018.4.16)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /usr/local/lib/python3.6/site-packages (from requests) (1.22)
snowdream$ pip install netifaces
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: netifaces in /usr/local/lib/python3.6/site-packages (0.10.7)
 snowdream$ pip list
Package    Version  
---------- ---------
certifi    2018.4.16
chardet    3.0.4    
idna       2.6      
meson      0.45.0   
netifaces  0.10.7   
pip        10.0.1   
requests   2.18.4   
setuptools 38.5.1   
urllib3    1.22     
wheel      0.30.0   

提个小建议

用阿里云的基本上都是**人啦~
感觉README直接写中文不就好咯。

Failed to Update

Got the error returned from dns.aliyun.com:
image

The parameters:
image

Call stack:
image

MissingTimestamp

hi, I Got MissingTimestamp ERROR, and I found

{"Message":"Timestamp is mandatory for this action.","RequestId":"XXXXXXXXXX","HostId":"dns.aliyuncs.com","Code":"MissingTimestamp"}

It means "MissingTimestamp"....

Since Aug 20, 2017

        commonParams = {
            'Format': 'json',
            'Version': '2015-01-09',
            'AccessKeyId': self.accessKeyId,
            'TimeStamp': self.getTimeStamp(),
            'SignatureMethod': 'HMAC-SHA1',
            'SignatureNonce': self.getSignatureNonce(),
            'SignatureVersion': "1.0",
        }

goes into

        commonParams = {
            'Format': 'json',
            'Version': '2015-01-09',
            'AccessKeyId': self.accessKeyId,
            'Timestamp': self.getTimeStamp(),
            'SignatureMethod': 'HMAC-SHA1',
            'SignatureNonce': self.getSignatureNonce(),
            'SignatureVersion': "1.0",
        }

sub domain为*或者@时解析有问题

sub domain为*或者@时解析有问题
根据阿里云的定义,*代表任意二级域名,@代表没有指定二级域名
似乎client在这块儿支持得有问题

=======ddns.conf====
...
[DomainRecord1]
domain = circleflow.net
sub_domain = *
type = A
...
========log=====
cd /opt/ddns/aliyun-ddns-client && /usr/bin/python ddns.py
2017-10-22 16:30:56 [ERROR] DomainRecord[.circleflow.net] cannot be resolved because of:[Errno -5] No address associated with hostname
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
2017-10-22 16:30:56 [INFO] Skipped as we already updated DomainRecord[
.circleflow.net]

in centos 6.8 SyntaxError: invalid syntax

[root@Esxi-Centos aliyun-ddns-client]# python3 ddns.py
Traceback (most recent call last):
File "ddns.py", line 21, in
from config import DDNSConfig
File "/opt/aliyun-ddns-client/config.py", line 79
print "No section: {0}".format(section)
^
SyntaxError: invalid syntax

如何解析局域网地址

我的配置文件如下, 但是我的DomainRecord1的域名还是走了公网, 我指定了interface, 我如何用这个网卡的ip呢?(也就是局域网地址)

netifaces 已安装

[DEFAULT]
# Required: access id obtains from aliyun
access_id=隐藏
# Required: access key obtains from aliyun
access_key=隐藏
# Optional: not used now
interval=600
# Optional: turn on debug mode or not
debug=true

[DomainRecord1]
# Required: domain name, like google.com
domain=隐藏.com
# Required: subdomain name, like: *, www, blog, bbs
sub_domain=pi4
# Required: resolve IPV6 address
#type=A
# Option: Deafult Interface is eno1
interface=wlan0


[feature_public_ip_from_nic]
enable=false
interface=eth0

one small typo

ddns.py line 53:
DDNSUtils.info("current public ip is:{0}, server ip is:%s".format(currentPublicIP, localRecord.value))
%s should be {1}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.