-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomain.py
59 lines (58 loc) · 1.42 KB
/
domain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import urllib.request
import json
import urllib.request
from bs4 import BeautifulSoup
import socket
import time
from urllib.error import URLError
from retry import retry
def get_ip():
#获取当前ip
url = 'http://www.net.cn/static/customercare/yourip.asp'
req = urllib.request.Request(url)
rsp=urllib.request.urlopen(req)
html=rsp.read().decode('utf-8',"ignore")
html=BeautifulSoup(html,'html.parser')
iph2=html.h2
global ip
ip=iph2.get_text()
get_ip()
ip_addr = ip
#修改域名
api_url = 'https://api.godaddy.com/v1/domains/你的域名/records'
head = {}
head['Accept'] = 'application/json'
head['Content-Type'] = 'application/json'
#api key
head['Authorization'] = 'sso-key 你的key:你的secret'
records_a = {
"data" : ip_addr,
"name" : "@",
"ttl" : 600,
"type" : 'A',
}
records_NS01 = {
"data" : "ns07.domaincontrol.com",
"name" : "@",
"ttl" : 3600,
"type" : "NS",
}
records_NS02 = {
"data" : "ns08.domaincontrol.com",
"name" : "@",
"ttl" : 3600,
"type" : "NS",
}
put_data = [records_a,records_NS01,records_NS02]
while True:
try:
req = urllib.request.Request(api_url,headers = head,data = json.dumps(put_data).encode(),method = "PUT")
rsp = urllib.request.urlopen(req)
code = rsp.getcode()
if code == 200:
print('成功更改域名解析:'+ip_addr)
break
else:
print('更改失败!')
except:
print("错误")