加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ddns.py 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
XuChao 提交于 2017-09-13 23:41 . add ddns.service
#!/usr/bin/python
# -*- coding: utf-8 -*-
import threading
from sdkwrapper import AliYunSdkWrapper
from util import Util
from config import Config
CONFIG_FILE = "ddns.conf"
def main():
"""
Main Function
"""
"""
load config
"""
ddnsConfig = Config()
if ddnsConfig.loadConfig(CONFIG_FILE):
"""
get current local internet ip
"""
local_ip = Util.getLocalInternetIp()
if local_ip[0]:
"""
init AliYunSdkWrapper
"""
sdkUtil = AliYunSdkWrapper(
ddnsConfig.access_key_id,
ddnsConfig.access_key_secret,
ddnsConfig.domain_name,
ddnsConfig.sub_domain_name,
ddnsConfig.record_type,
ddnsConfig.region_id
)
"""
update record
"""
sdkUtil.updateRecord(local_ip[1])
scheduleTimerTask(ddnsConfig.interval * 60)
else:
print local_ip[1]
scheduleTimerTask(ddnsConfig.interval * 60)
else:
print "not config yet , retry 1 min later...... 【Skip】"
scheduleTimerTask(1 * 60)
def scheduleTimerTask(interval):
timer = threading.Timer(interval, main)
timer.start()
if __name__ == "__main__":
print "ali-ddns run ..."
scheduleTimerTask(3)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化