码迷,mamicode.com
首页 > 编程语言 > 详细

花生壳动态IP域名解析之python自动提交公网IP

时间:2015-05-22 18:56:05      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

#!/usr/bin/env python
import re
import os
import time
import random

ip_current = ‘‘
while True:
    myip = re.findall(r‘\d+\.\d+\.\d+\.\d+‘,os.popen(‘curl -s http://ddns.oray.com/checkip‘).read())
    print time.strftime("%Y-%m-%d %H:%M:%S")
    print ‘current public ip is‘, myip
    if myip and myip != ip_current:
        print ‘current public ip has changed‘
        ip_current = myip
        webinfo = os.popen(‘curl -s http://用户名:密码@ddns.oray.com/ph/update?hostname=域名&myip=‘).read()
        print ‘commit info:‘, webinfo
        if ‘good‘ in webinfo:
            print ‘result: commit ok‘
        elif ‘nochg‘ in webinfo:
            print ‘result: no change‘
        else:
            print ‘result: commit failure‘
    else:
        print ‘current public ip has not changed‘
    print ‘---‘
    time.sleep(random.randint(300,600))

  最后编辑开机启动项文件/etc/rc.local,添加路径:/home/shenwenkai/activeip.py

花生壳动态IP域名解析之python自动提交公网IP

标签:

原文地址:http://www.cnblogs.com/shenwenkai/p/4522839.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!