Пример #1
0
    def __init__(self):
        self.API_TEMPLATE = 'https://api.ote-godaddy.com/v1'

        self.account = godaddypy.Account(_API_KEY, _API_SECRET)

        # Create a Client and override the API to use the test API
        self.client = godaddypy.Client(self.account)
        self.client.API_TEMPLATE = self.API_TEMPLATE
Пример #2
0
def main():
    #logging.basicConfig(format='%(asctime)s%(levelname)s:%(message)s', level=logging.DEBUG)

    # Recover configuration
    api_key = config["key"]
    api_sec = config["secret"]
    domain = config["domain"]
    host = config["host"]
    type = config["type"]
    ttl = config["ttl"]

    # Create Godaddy account and client
    godaddy_account = godaddypy.Account(api_key=api_key, api_secret=api_sec)
    godaddy_client = godaddypy.Client(godaddy_account)

    # Get current public IP address
    public_ip = urllib.request.urlopen('https://ident.me').read().decode(
        'utf8')

    # Get current record
    records = godaddy_client.get_records(domain, record_type=type)
    # Get current IP address
    current_ip = records[0]["data"]  #old: 1

    # If public and current address are equal, return
    if (current_ip == public_ip):
        logging.info(
            "No update required; both IP addresses are the same (IP={})!".
            format(current_ip))
        return

    # Otherwise, set public address to current address
    result = godaddy_client.update_record_ip(public_ip, domain, host, type)
    if (result == False):
        logging.error(
            "Error updating public IP address (IP={})!".format(current_ip))
    else:
        logging.error("Updated public IP address (IP={})!".format(public_ip))
Пример #3
0
import godaddypy

if "GD_KEY" not in os.environ:
    raise Exception(
        "Missing Godaddy API-key in GD_KEY environment variable! Please register one at https://developer.godaddy.com/keys/"
    )

if "GD_SECRET" not in os.environ:
    raise Exception(
        "Missing Godaddy API-secret in GD_SECRET environment variable! Please register one at https://developer.godaddy.com/keys/"
    )

api_key = os.environ["GD_KEY"]
api_secret = os.environ["GD_SECRET"]
my_acct = godaddypy.Account(api_key=api_key, api_secret=api_secret)
client = godaddypy.Client(my_acct)

logger = logging.getLogger(__name__)
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.INFO)


def _get_zone(domain):
    parts = domain.split(".")
    zone_parts = parts[-2::]
    zone = ".".join(zone_parts)
    return zone


def _get_subdomain_for(domain, zone):
    subdomain = domain[0:(-len(zone) - 1)]
Пример #4
0
  passno+=1
  if (passno>10):
    sleepsecs=300
  time.sleep(sleepsecs)
  currip=pif.get_public_ip()

  # Did the IP address change since last time?
  if (previp!=currip):
    if (previp=="none"):
      say("Initial IP address is "+currip+".")
    else:
      say("IP changed from "+previp+" to "+currip+".")

    try:
      acct=godaddypy.Account(api_key=publickey,api_secret=privatekey)
      client=godaddypy.Client(acct)
      say("Logged into GoDaddy.")

      # Loop through domains to be updated
      for domain in domainlist:
        try:
          ok=client.update_record_ip(currip,domain,name='@',record_type='A')
          if ok:
            say(" ... successfully updated "+domain+".")
          else:
            say(" ... unable to update "+domain+"!!!")
        except:
          say("Error updating domain "+domain+":")
          say("  "+sys.exc_info()[1])
        # end try updating domain
      # end for each domain in the list
# Required ENV
godaddy_api_key = get_config_value('GODADDY_API_KEY')
godaddy_api_secret = get_config_value('GODADDY_API_SECRET')
godaddy_domains = get_config_value('GODADDY_DOMAINS').split(',')

# Optional ENV
godaddy_a_names = get_config_value('GODADDY_A_NAMES', '@').split(',')
get_ip_wait_sec = get_config_value('GET_IP_WAIT_SEC', 10)  # default 10 sec
update_interval_sec = get_config_value('UPDATE_INTERVAL_SEC',
                                       900)  # default 15 min
ipv6_get_api = get_config_value(
    'IPV6_GET_API', 'https://api6.ipify.org')  # default https://api6.ipify.org
record_type = get_config_value('RECORD_TYPE', 'A')  # default 'A'

# Create the godaddypy client using the provided keys
g_client = godaddypy.Client(
    godaddypy.Account(api_key=godaddy_api_key, api_secret=godaddy_api_secret))


def url_postget(url):
    response = urllib.request.urlopen(url)
    str = response.read()
    return str


def update_godaddy_records(ip):

    successful = True
    for domain in godaddy_domains:
        for a_name in godaddy_a_names:

            logging.debug('Getting A records with {} for {}'.format(
ipv4 = False
ipv6 = False
try:
    ipv4 = requests.get('https://v4.ident.me/').content.decode()
except requests.exceptions.ConnectionError:
    logging.warn('GoDaddyUpdater: Cannot get current IPv4-Address')

try:
    ipv6 = requests.get('https://v6.ident.me/').content.decode()
except requests.exceptions.ConnectionError:
    logging.warn('GoDaddyUpdater: Cannot get current IPv6-Address')

# call godaddy api
account = godaddypy.Account(api_key=GODADDY_PUBLIC_KEY,
                            api_secret=GODADDY_SECRET_KEY)
client = godaddypy.Client(account)

for domain, subdomains in DOMAINS.items():
    if isinstance(subdomains, str):
        subdomains = [subdomains]

    if isinstance(subdomains, bool) and subdomains == True:
        subdomains = ['@']

    new_records = []
    for subdomain in subdomains:
        if ipv4:
            new_records.append({
                'data': ipv4,
                'name': subdomain,
                'ttl': DOMAIN_TTL,
Пример #7
0
def godaddyapi(key, secret):  # Returns godaddy API Client object.
    a = godaddypy.Account(api_key=key, api_secret=secret)
    return godaddypy.Client(a)