树莓派raspbian实现ddns搭建linux nginx mysql php adsl顶级域名动态解析服务器

作者:小鱼的互联网观察 发布时间:January 29, 2014 分类:linux

树莓派raspbian实现ddns搭建linux nginx mysql php adsl服务器


以下是python脚本


#!/usr/bin/env python
#-*- coding:utf-8 -*-
 
import httplib, urllib
import socket
import time
 
params = dict(
    login_email="[email protected]", # replace with your email
    login_password="password!", # replace with your password
    format="json",
    domain_id=111111, # replace with your domain_od, can get it by API Domain.List
    record_id=1111111, # replace with your record_id, can get it by API Record.List
    sub_domain="adsl", # replace with your sub_domain
    record_line="默认",
)
current_ip = None
 
def ddns(ip):
    params.update(dict(value=ip))
    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/json"}
    conn = httplib.HTTPSConnection("dnsapi.cn")
    conn.request("POST", "/Record.Ddns", urllib.urlencode(params), headers)
    
    response = conn.getresponse()
    print response.status, response.reason
    data = response.read()
    print data
    conn.close()
    return response.status == 200
 
def getip():
    sock = socket.create_connection(('ns1.dnspod.net', 6666))
    ip = sock.recv(16)
    sock.close()
    return ip
 
if __name__ == '__main__':
    while True:
        try:
            ip = getip()
            print ip
            if current_ip != ip:
                if ddns(ip):
                    current_ip = ip
        except Exception, e:
            print e
            pass
        time.sleep(30)



保存以上代码为 ddns.py


在ssh执行:

nohup python ddns.py &


(注意后面的 & 前有个空格)

ok 这个python 程序就在后台运行了,


raspbian 安装 ddns搭建动态解析ip

标签: 树莓派raspbian实现ddns搭建linux nginx mysql php adsl服务器

互联网观察
树莓派raspbian实现ddns搭建linux nginx mysql php adsl顶级域名动态解析服务器
本文地址:http://tianmeng.org/archives/396/

相关文章

  • 无相关文章
文档信息

当前暂无评论 »

网站地图 京ICP证030173号