我想更新我的GoDaddy IP。代码有效,但我想得到一份报告。
Python代码:
#!/usr/bin/env python
import urllib.request
import os
def oldip():
file = open('oldip.txt')
return file.read()
def newip():
url = urllib.request
site = url.urlopen('http://ipecho.net/plain')
ip = site.read()
ip = str(ip)
ip = ip.strip("b")
ip = ip.replace("'", "")
#print(ip)
return ip
oldip=oldip()
newip=newip()
maindomain="karaliyor.com"
subdomain="@"
if newip!=oldip:
#print("IP change!")
PublicIP=newip
print(PublicIP)
os.system('/home/pi/Desktop/godaddy_deneme/alo.sh "'+maindomain+'" "'+subdomain+'" "'+PublicIP+'"')
Bash代码
Key='blabla'
Secret='blabla'
maindomain="$1"
subdomain="$2"
PublicIP="$3"
curl -X PUT https://api.godaddy.com/v1/domains/${maindomain}/records/A/${subdomain} -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: sso-key ${Key}:${Secret}" -d "[ { \"data\": \"${PublicIP}\", \"ttl\": 600 }]" >>/home/pi/Desktop/godaddy_deneme/out.txt 2>&1
out.txt内容:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 51 0 0 100 51 0 51 0:00:01 --:--:-- 0:00:01 51
如何获取返回码?
为什么out.txt文件的内容? :d