Code Monkey home page Code Monkey logo

aliyun_ddns's Introduction

aliyun_ddns --基于阿里云解析的动态域名解析

之前考虑的方案是使用小米路由器ddns+花生壳,然而看到花生壳恶心的域名名称后果断放弃了,加之其免费的动态域名解析服务的口碑都是出奇的慢,之前也使用过,速度确实没法玩耍。

更新 2022.01

  • 更换ip源
  • 支持ipv6

为何要写这个

为了达到使用域名即可访问家里服务的目的,需要两个条件,外网ip和域名。

域名这个简单,在阿里云购买一个即可,麻烦的是ip,由于目前家庭使用的宽带基本上都是服务商动态分配的ip(有的甚至只分配内网ip,这个需要打电话给服务商要回外网ip!)这样的话,域名解析就没法玩了,此时需要动态域名解析,能够在家里ip变化的时候更新解析记录。

当然可以使用花生壳,但是开头已经提到了两个蛋疼的原因,所以,这个工具脚本需求就来了!

实现方法

定时检测自家外网ip地址,有变化就调用阿里云解析的api修改域名解析。

前提条件

  1. 确保自己拥有外网ip
  2. 使用阿里云解析,申请access_key
  3. 首先在阿里云解析中新增域名的解析记录 (重要!!!因为本脚本只是修改,所以前提得有可修改的解析记录!!!)

脚本依赖

  1. python环境 (安装python2.7, 不支持python3)
  2. pip install requests

使用说明

  1. 修改aliyun_settings.json中的access_key、access_secret为自己申请的accesskey
  2. 修改aliyun_settings.json中的domain为自己要解析的域名,比如 "baidu.com''
  3. 定时执行 python aliyun_ddns.py (windows和linux环境下的定时任务就不提了)
  4. 最新的ip会保存在同级目录的ip.txt中,方便查看
  5. 脚本的执行步骤有print日志,如有问题,先分析下输出内容

注意

修改完解析记录后并不会马上生效,因为dns服务都有缓存,所以得等,阿里云的解析ttl可以设置的最小值为10分钟,所以有时候得等一会才能生效。 如果迟迟不生效,首先登录阿里云控制台查看解析记录是否成功修改,如果已经修改,那么就是dns服务的缓存问题了,这个基本就是死等。。。

aliyun_ddns's People

Contributors

aixiang avatar limoxi 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

aliyun_ddns's Issues

requests.get(REQUEST_URL, get_params) 这句遇到错误

requests.get(REQUEST_URL, get_params) 这句遇到:

Traceback (most recent call last):
  File "aliyun_ddns.py", line 123, in 
    update_yun(ip)
  File "aliyun_ddns.py", line 76, in update_yun
    get_resp = requests.get(REQUEST_URL, get_params)
TypeError: get() takes exactly 1 argument (2 given)

REQUEST_URL: https://alidns.aliyuncs.com/
get_params: {'SignatureVersion': '1.0', 'DomainName': u'xxx', 'Timestamp': 'xxx', 'Format': 'json', 'SignatureMethod': 'HMAC-SHA1', 'AccessKeyId': u'xxx', 'TypeKeyWord': 'A', 'Version': '2015-01-09', 'Signature': 'xxx', 'Action': 'DescribeDomainRecords', 'SignatureNonce': UUID('xxx')}

这报错是什么原因

update remote record...
get_records============
{u'Code': u'Forbidden.RAM', u'Message': u"User not authorized to operate on the specified resource, or this API doesn't support RAM.", u'HostId': u'alidns.aliyuncs.com', u'RequestId': u'3AFE62CC-8458-46C7-811A-BA0B60299256'}
Traceback (most recent call last):
File "aliyun_ddns.py", line 124, in
update_yun(ip)
File "aliyun_ddns.py", line 78, in update_yun
for record in records['DomainRecords']['Record']:
KeyError: 'DomainRecords'

百度的ip解析没了,需要更换一下ip解析地址

rt:
我修改了一下解析的地址,修改get_curr_ip 方法如下

def get_curr_ip():
        headers = {
                'content-type': 'text/html',
                'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0'
        }
        resp = requests.get('http://ip.tool.chinaz.com/', headers=headers)
        soup = BS(resp.content, 'html.parser')
        return soup.select('.fz24')[0].string

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.