欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python腳本實(shí)現(xiàn)DNSPod DNS動(dòng)態(tài)解析域名

 更新時(shí)間:2015年02月14日 10:57:57   投稿:junjie  
這篇文章主要介紹了Python腳本實(shí)現(xiàn)DNSPod DNS動(dòng)態(tài)解析域名,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下

閑暇之余,在家里自建了個(gè)服務(wù)器,因?yàn)橛玫男^(qū)寬帶,IP位動(dòng)態(tài)分配。域名解析就是個(gè)問(wèn)題,我的域名一般停放在DNSPod下。DNSPod有提供修改的API,就用Python簡(jiǎn)單的實(shí)現(xiàn)了一下動(dòng)態(tài)解析。這樣,就不用安裝花生殼了。 廢話不說(shuō),看代碼:

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

import httplib, urllib, urllib2
import time
import sys,os
import re
import json

username = 'xxxx' #賬號(hào)
password = 'xxx' #密碼
format = 'json'

domain = [u'www.youdomain.com'] #要解析的域名

def get_domain_info(domain):
  domain_split = domain.split('.')
  domain_split_len = len(domain_split)
  maindomain = domain_split[domain_split_len - 2] + '.' + domain_split[domain_split_len - 1]
  return maindomain,domain

params = {'login_email':username,'login_password':password,'format':format}

def request(action, params, method = 'POST'):
  headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/json"}
  conn = httplib.HTTPSConnection("dnsapi.cn")
  conn.request(method, '/' + action, urllib.urlencode(params), headers)
  response = conn.getresponse()
  data = response.read()
  conn.close()
  if response.status == 200:
    return data
  else:
    return None

def get_my_domain_id():
  data = request('Domain.List',params)
  data = json.loads(data)
  domainlist = data.get('domains')
  domaninfo = {}
  for d in domainlist:
    domaninfo[d.get('name')] = d.get('id')
  return domaninfo

def get_my_domain_record_id(domain_id):
  params['domain_id'] = domain_id
  data = request('Record.List',params)
  data = json.loads(data)
  if data.get('code') == '10':
    return None
  domainname = data.get('domain').get('name')
  record_list = data.get('records')
  record = {}
  for r in record_list:
    if r.get('type') == 'A':
      key = r.get('name') != '@' and r.get('name') + '.' + domainname or domainname
      record[key] = {'id':r.get('id'),'value':r.get('value')}
  return record

def changerecord(domain,domain_id,record_id,ip):
  params['domain_id'] = domain_id
  params['record_id'] = record_id
  params['record_type'] = 'A'
  params['record_line'] = '默認(rèn)'
  params['sub_domain'] = domain
  params['ttl'] = 600
  params['value'] = ip
  data = request('Record.Modify',params)

def getip():
  url = 'http://iframe.ip138.com/ic.asp'
  response = urllib2.urlopen(url)
  text = response.read()
  ip = re.findall(r'\d+.\d+.\d+.\d+', text)
  return ip[0] or None

def updatedomaininfo(domain):
  m,sub_m = get_domain_info(domain)
  domain_id = my_domain_id_list.get(m)
  record_list = get_my_domain_record_id(domain_id)
  if record_list == None:
    return None
  rocord_info = record_list.get(sub_m)
  record_ip = rocord_info.get('value')
  record_id = rocord_info.get('id')
  return sub_m,record_ip,record_id,domain_id

if __name__ == '__main__':
  my_domain_id_list = get_my_domain_id()
  try:
    for dm in domain:
      domaindata = updatedomaininfo(dm)
      if domaindata == None:
        continue
      dnsdomain,dnsdmainip,record_id,domain_id = domaindata
      domain_name = dnsdomain.split('.')[0]
      ip = getip()
      if ip == dnsdmainip:
        continue
      else:
        changerecord(domain_name,domain_id,record_id,ip)
  except:
    pass

相關(guān)文章

  • Jupyter notebook命令和編輯模式常用快捷鍵匯總

    Jupyter notebook命令和編輯模式常用快捷鍵匯總

    這篇文章主要介紹了Jupyter notebook命令和編輯模式常用快捷鍵匯總,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-11-11
  • python判斷windows系統(tǒng)是32位還是64位的方法

    python判斷windows系統(tǒng)是32位還是64位的方法

    這篇文章主要介紹了python判斷windows系統(tǒng)是32位還是64位的方法,實(shí)例分析了兩種解決方法,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下
    2015-05-05
  • Python基于xlrd模塊處理合并單元格

    Python基于xlrd模塊處理合并單元格

    這篇文章主要介紹了Python基于xlrd模塊處理合并單元格,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-07-07
  • Python環(huán)境搭建之OpenCV的步驟方法

    Python環(huán)境搭建之OpenCV的步驟方法

    本篇文章主要介紹了Python環(huán)境搭建之OpenCV的步驟方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-10-10
  • python函數(shù)enumerate,operator和Counter使用技巧實(shí)例小結(jié)

    python函數(shù)enumerate,operator和Counter使用技巧實(shí)例小結(jié)

    這篇文章主要介紹了python函數(shù)enumerate,operator和Counter使用技巧,結(jié)合實(shí)例形式總結(jié)分析了python內(nèi)置函數(shù)enumerate,operator和Counter基本功能、原理、用法及操作注意事項(xiàng),需要的朋友可以參考下
    2020-02-02
  • python中 logging的使用詳解

    python中 logging的使用詳解

    這篇文章主要介紹了python中 logging的使用,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-10-10
  • SQLite5-使用Python來(lái)讀寫(xiě)數(shù)據(jù)庫(kù)

    SQLite5-使用Python來(lái)讀寫(xiě)數(shù)據(jù)庫(kù)

    這篇文章主要介紹了SQLite5-使用Python來(lái)讀寫(xiě)數(shù)據(jù)庫(kù),數(shù)據(jù)庫(kù)的實(shí)際應(yīng)用,通常需要與程序結(jié)合起來(lái),通過(guò)程序來(lái)實(shí)現(xiàn)對(duì)數(shù)據(jù)庫(kù)的訪問(wèn)和讀寫(xiě)。本篇先介紹Python語(yǔ)言來(lái)調(diào)用SQLite數(shù)據(jù)庫(kù),想具體了解的小伙伴可以參考一下</P><P>
    2021-12-12
  • python編程實(shí)現(xiàn)希爾排序

    python編程實(shí)現(xiàn)希爾排序

    這篇文章主要介紹了python實(shí)現(xiàn)希爾排序,已編程實(shí)現(xiàn)的希爾排序,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Python實(shí)現(xiàn)http接口自動(dòng)化測(cè)試的示例代碼

    Python實(shí)現(xiàn)http接口自動(dòng)化測(cè)試的示例代碼

    這篇文章主要介紹了Python實(shí)現(xiàn)http接口自動(dòng)化測(cè)試的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • Python 實(shí)現(xiàn)3種回歸模型(Linear Regression,Lasso,Ridge)的示例

    Python 實(shí)現(xiàn)3種回歸模型(Linear Regression,Lasso,Ridge)的示例

    這篇文章主要介紹了Python 實(shí)現(xiàn) 3 種回歸模型(Linear Regression,Lasso,Ridge)的示例,幫助大家更好的進(jìn)行機(jī)器學(xué)習(xí),感興趣的朋友可以了解下
    2020-10-10

最新評(píng)論