Added an info mode to display infos about a subdomain
This commit is contained in:
parent
0fc975a429
commit
fec16b00df
1 changed files with 12 additions and 1 deletions
13
gandyndns.py
13
gandyndns.py
|
|
@ -9,6 +9,7 @@ parser = argparse.ArgumentParser(
|
||||||
description="A script which connect to Gandi.net API to change IP associated to a DNS record")
|
description="A script which connect to Gandi.net API to change IP associated to a DNS record")
|
||||||
parser.add_argument("-v", "--verbose",
|
parser.add_argument("-v", "--verbose",
|
||||||
help="Enable verbose mode", action="store_true")
|
help="Enable verbose mode", action="store_true")
|
||||||
|
parser.add_argument("-i", "--info", help="Enable information mode and retrieves information about the subdomain", action="store_true")
|
||||||
parser.add_argument("domain", metavar="DOMAIN",
|
parser.add_argument("domain", metavar="DOMAIN",
|
||||||
help="The domain for which you want to write a DNS record. Example: example.com")
|
help="The domain for which you want to write a DNS record. Example: example.com")
|
||||||
parser.add_argument("subdomain", metavar="SUBDOMAIN",
|
parser.add_argument("subdomain", metavar="SUBDOMAIN",
|
||||||
|
|
@ -24,6 +25,7 @@ args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
verbose = args.verbose
|
verbose = args.verbose
|
||||||
|
info_mode = args.info
|
||||||
domain = args.domain
|
domain = args.domain
|
||||||
apikey = args.apikey
|
apikey = args.apikey
|
||||||
subdomain = args.subdomain
|
subdomain = args.subdomain
|
||||||
|
|
@ -79,6 +81,10 @@ def retrieve_dns_ip(api_url, headers):
|
||||||
retrieved_dns_ip = ""
|
retrieved_dns_ip = ""
|
||||||
return retrieved_dns_ip, retrieved_ttl
|
return retrieved_dns_ip, retrieved_ttl
|
||||||
|
|
||||||
|
def retrieve_rrset(api_url, headers):
|
||||||
|
response = requests.get(api_url, headers=headers)
|
||||||
|
response_json = response.json()
|
||||||
|
return response_json
|
||||||
|
|
||||||
def update_dns_ip(api_url, headers):
|
def update_dns_ip(api_url, headers):
|
||||||
"""Updates the IP in the DNS record using the IP provided (acquired by retrieve_public_ip) if it is different from the DNS IP"""
|
"""Updates the IP in the DNS record using the IP provided (acquired by retrieve_public_ip) if it is different from the DNS IP"""
|
||||||
|
|
@ -124,4 +130,9 @@ def update_dns_ip(api_url, headers):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
update_dns_ip(api_url, headers)
|
if info_mode:
|
||||||
|
print("Retrieving information\nIf this fails, don't forget to check if the record type is correct.")
|
||||||
|
print("-------------------------------------------------------------------")
|
||||||
|
print(retrieve_rrset(api_url, headers))
|
||||||
|
else:
|
||||||
|
update_dns_ip(api_url, headers)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue