1

I want to update my GoDaddy IPs. The codes works, but I want to get a report.

Python Codes:

#!/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 Codes

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 content:

  % 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

How do I get the return code?

Why does the contents of the out.txt file? :D

  • Possible duplicate of [Calling an external command in Python](https://stackoverflow.com/questions/89228/calling-an-external-command-in-python) – Ondrej K. Jun 10 '18 at 18:49

0 Answers0