日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

阿里云dns 接口调用/代码

發布時間:2023/12/8 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 阿里云dns 接口调用/代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
主程序 幾個函數調用阿里云接口 flask前端交互 加入http認證 很low的代碼 只作為測試使用 #!/usr/bin/env python #encoding: utf-8 from flask import Flask, render_template, request, flash from flask_httpauth import HTTPBasicAuth from aliyunsdkalidns.request.v20150109 import AddDomainRequest, AddDomainRecordRequest, DescribeDomainRecordsRequest,DescribeRecordLogsRequest from aliyunsdkcore import client import redis import json # import urllib, urllib2app = Flask(__name__) app.secret_key = 'kjsensldfneapk' auth = HTTPBasicAuth() #http users = [{'username': 'admin', 'password': 'admin'}, ]r = redis.StrictRedis(host='172.16.10.133', port=31350, db=0) # a={'Action': 'ADD', 'ActionTimestamp': 1515035872000L, 'Message': '\xe6\x96\xb0\xe5\xa2\x9e\xe8\xa7\xa3\xe6\x9e\x90\xe8\xae\xb0\xe5\xbd\x95 A\xe8\xae\xb0\xe5\xbd\x95 blog \xe9\xbb\x98\xe8\xae\xa4 61.128.128.68 ( TTL: 600) ', 'ActionTime': '2018-01-04T11:17Z', 'ClientIp': '14.105.38.140'}, {'Action': 'DEL', 'ActionTimestamp': 1514960338000L, 'Message': '\xe5\x88\xa0\xe9\x99\xa4\xe8\xa7\xa3\xe6\x9e\x90\xe8\xae\xb0\xe5\xbd\x95 A\xe8\xae\xb0\xe5\xbd\x95 pay \xe9\xbb\x98\xe8\xae\xa4 172.16.10.25 ( TTL: 600)', 'ActionTime': '2018-01-03T14:18Z', 'ClientIp': '14.105.38.140'} # b=str(a) # print b # r.set('A',b) # r.set('A','{'Action': 'ADD', 'ActionTimestamp': 1515035872000L, 'Message': '\xe6\x96\xb0\xe5\xa2\x9e\xe8\xa7\xa3\xe6\x9e\x90\xe8\xae\xb0\xe5\xbd\x95 A\xe8\xae\xb0\xe5\xbd\x95 blog \xe9\xbb\x98\xe8\xae\xa4 61.128.128.68 ( TTL: 600) ', 'ActionTime': '2018-01-04T11:17Z', 'ClientIp': '14.105.38.140'}, {'Action': 'DEL', 'ActionTimestamp': 1514960338000L, 'Message': '\xe5\x88\xa0\xe9\x99\xa4\xe8\xa7\xa3\xe6\x9e\x90\xe8\xae\xb0\xe5\xbd\x95 A\xe8\xae\xb0\xe5\xbd\x95 pay \xe9\xbb\x98\xe8\xae\xa4 172.16.10.25 ( TTL: 600)', 'ActionTime': '2018-01-03T14:18Z', 'ClientIp': '14.105.38.140'}') # print r.get('db')#阿里云相關認證 # access_key_id = "xxxx" access_key_id = "xxxx" # access_Key_secret = "xx" access_Key_secret = "xxxxx" # Version = "2015-01-09" # #主域名 # rc_domain = "youngblog.cc" # #請填寫你的解析記錄 # rc_rr = 'pay' # #需要添加的記錄 # rc_add = 'blog' # #客服端ip # rc_ip= "61.128.128.68" # #請填寫返還內容格式,json,xml rc_format = 'json' #檢查域名是否存在 # def check_records(dns_domain): # # clt = client.AcsClient(access_key_id, access_Key_secret, 'cn-hangzhou') # clt = client.AcsClient(access_key_id, access_Key_secret) # request = DescribeDomainRecordsRequest.DescribeDomainRecordsRequest() # request.set_DomainName(dns_domain) # request.set_accept_format(rc_format) # result = clt.do_action_with_exception(request) # return resultdef add_dns(dns_domain,dns_add,dns_value,dns_type,dns_format):#阿里云dns 調用請參考 https://github.com/aliyun/aliyun-openapi-python-sdk/tree/master/aliyun-python-sdk-alidns/aliyunsdkalidns/request/v20150109clt = client.AcsClient(access_key_id, access_Key_secret)# request = AddDomainRequest.AddDomainRequest()#方法調用錯誤request = AddDomainRecordRequest.AddDomainRecordRequest()request.set_DomainName(dns_domain)request.set_RR(dns_add)request.set_Value(dns_value)request.set_Type(dns_type)request.set_accept_format(dns_format)result = clt.do_action_with_exception(request)# print resultreturn result ###獲取操作記錄 def get_domain(dns_domain,dns_format):clt = client.AcsClient(access_key_id, access_Key_secret)request = DescribeRecordLogsRequest.DescribeRecordLogsRequest()request.set_DomainName(dns_domain)request.set_accept_format(dns_format)result = clt.do_action_with_exception(request)#eval 轉換json不能識別中文,這里使用json.loads進行轉換return json.loads(result)['RecordLogs']['RecordLog'][0:10]#轉換后中文亂碼 等待從redis中讀取后再處理# return eval(result)['RecordLogs']['RecordLog'][0:10] # print get_domain(rc_domain,rc_format)def getinfoRdis():for k,v in enumerate(get_domain(rc_domain,rc_format)):str_v=str(v)r.set(k,str_v)return eval(r.get(0))['Message']##http 認證 @auth.get_password def get_password(username):for user in users:if user['username'] == username:return user['password']return None # print check_records(rc_domain) # print add_dns(rc_domain,rc_add,rc_ip,"A",rc_format)# def post_url(url, data): # req = urllib2.Request(url) # data = urllib.urlencode(data) # opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) # resp = opener.open(req, data) # return resp.read()# # flask 應用部分 @app.route('/', methods=["GET", "POST"]) @auth.login_required def index():if request.method == 'POST':domain = request.form['domain']adddomain = request.form['adddomain']ip_value = request.form['ip_value']dnstype = request.form['dnstype']if adddomain == "cahsier" or adddomain == "image" or adddomain == "pay" or adddomain == "merch" or adddomain == "www" or adddomain == "":flash(u'過濾敏感信息')return render_template('index.html')c = add_dns(domain,adddomain,ip_value,dnstype,'json')print cflash(u'更新域名完成請稍后查看')print "相關地址:domain,adddomain,ip_value,dnstype",domain,adddomain,ip_value,dnstypeif request.method == 'GET':# flash(get_domain(rc_domain,rc_format))flash(getinfoRdis())# print add_dns(rc_domain,rc_add,rc_ip,"A",rc_format)return render_template('index.html')# elif request.method == 'GET':if __name__ == '__main__':app.run(host='0.0.0.0', port=8081) 前端代碼: <!DOCTYPE html> <html> <head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>添加域名解析</title><!-- Tell the browser to be responsive to screen width --><meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"><!-- Bootstrap 3.3.6 --><link rel="stylesheet" href="/static/css/bootstrap.min.css"><!-- Font Awesome --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css"><!-- Ionicons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css"><!-- Theme style --><link rel="stylesheet" href="/static/css/AdminLTE.min.css"><!-- iCheck --><link rel="stylesheet" href="/static/css/blue.css"> </head> <body class="hold-transition login-page"> <div class="login-box"><div class="login-logo"><a >添加域名解析</a></div><!-- /.login-logo --><div class="login-box-body"><form action="/" method="post"><div class="form-group has-feedback"><input type="text" name="domain" class="form-control" placeholder="域名" value="域名" readonly> {# <input type="text" name="domain" class="form-control" placeholder="youngblog.cc" value="youngblog.cc" readonly>#}<span class="glyphicon glyphicon-envelope form-control-feedback"></span></div><div class="form-group has-feedback"><input type="text" name="adddomain" class="form-control" placeholder="主機記錄/如blog"><span class="glyphicon glyphicon-lock form-control-feedback"></span></div><div class="form-group has-feedback"><input type="text" name="ip_value" class="form-control" value="61.128.158.218"><span class="glyphicon glyphicon-lock form-control-feedback"></span></div><div class="form-group has-feedback"><input type="text" name="dnstype" class="form-control" placeholder="A" value="A" readonly><span class="glyphicon glyphicon-lock form-control-feedback"></span></div>pay,merch,www.等域名不能解析,請填寫正確的IP地址,存在相同記錄會報錯<div class="row"><div class="col-xs-8"></div><!-- /.col --><div class="col-xs-4"><button type="submit" class="btn btn-primary btn-block btn-flat">確定</button></div><!-- /.col --></div></form><div class="social-auth-links text-center"></div><!-- /.social-auth-links --></div><!-- /.login-box-body -->{% block custom_message %}{% with messages = get_flashed_messages(with_categories=true) %}{% if messages %}<div class="select-bar"><ul style="margin:0 0 0 10px;padding:5px 10px;">{% for category, message in messages %}<li style="font-size:15px;">{{ message | safe }}</li>{% endfor %}</ul></div>{% endif %}{% endwith %}{% endblock %} </div>

目錄結構 css fonts 這些就直接在網上下載就行├── run.py ├── static │? ?├── css │? ?│? ?├── AdminLTE.css │? ?│? ?├── AdminLTE.min.css │? ?│? ?├── blue.css │? ?│? ?├── bootstrap.css │? ?│? ?├── bootstrap.css.map │? ?│? ?├── bootstrap.min.css │? ?│? ?├── bootstrap.min.css.map │? ?│? ?├── bootstrap-theme.css │? ?│? ?├── bootstrap-theme.css.map │? ?│? ?├── bootstrap-theme.min.css │? ?│? ?├── bootstrap-theme.min.css.map │? ?│? ?├── dataTables.bootstrap.css │? ?│? ?├── font-awesome.min.css │? ?│? ?└── ionicons.min.css │? ?└── fonts │? ? ? ?├── glyphicons-halflings-regular.eot │? ? ? ?├── glyphicons-halflings-regular.svg │? ? ? ?├── glyphicons-halflings-regular.ttf │? ? ? ?├── glyphicons-halflings-regular.woff │? ? ? ?└── glyphicons-halflings-regular.woff2 ├── templates │? ?└── index.html

總結

以上是生活随笔為你收集整理的阿里云dns 接口调用/代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。