DNSPod动态IP解析更新程序

脚本是Python写的,树莓派上可直接运行。

#!/usr/bin/env python
#-*- coding:utf-8 -*-

import httplib, urllib
import socket
import time

params = dict(
    login_email="email", # replace with your email
    login_password="password", # replace with your password
    format="json",
    domain_id=100, # replace with your domain_od, can get it by API Domain.List
    record_id=100, # replace with your record_id, can get it by API Record.List
    sub_domain="www", # 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)

阅读全文

使用WebIOPi控制树莓派的GPIO引脚电平

1、必须安装python开发版,即python-dev,不然后面很多软件都会安装不成功,提示目录无法找到之类的。

sudo apt-get install python-dev

正常情况下,以上在线安装命令即可安装成功,但运气不好的是,笔者在安装时,在线命令安装资源包404。
python2.7-dev_2.7.3~rc2-2.1_armhf.deb找不到,后来只能手动找了以下包安装。
阅读全文