Skip to content

Instantly share code, notes, and snippets.

@sq3
Last active February 24, 2021 16:00
Show Gist options
  • Save sq3/57936510825c95e79a61b818d5ecfa59 to your computer and use it in GitHub Desktop.
Save sq3/57936510825c95e79a61b818d5ecfa59 to your computer and use it in GitHub Desktop.
inwx DynDNS
#!/usr/sbin/python3
# -*- coding: utf-8 -*-
from requests.auth import HTTPBasicAuth
from requests.exceptions import HTTPError
import argparse
import logging
import os
import requests
import sys
log = logging.getLogger()
dyndns_url = 'https://dyndns.inwx.com/nic/update?myip='
ipfi_url = 'https://api.ipify.org'
def get_arguments():
log.debug('parsing arguments')
parser = argparse.ArgumentParser()
parser.add_argument(
'--user',
help='your inwx user',
action='store'
)
parser.add_argument(
'--password',
help='your inwx password',
action='store'
)
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
return parser
def get_ip():
try:
ip = requests.get((ipfi_url)).text
except HTTPError as http_error:
log.error(http_error)
return ip
def set_dns(ip, user, password):
try:
set_dns = requests.get((dyndns_url) + (ip), auth=((user), (password)))
print("Current puplic ip is " + (ip))
except HTTPError as http_error:
log.error(http_error)
else:
pass
def main():
try:
parser = get_arguments()
args = parser.parse_args()
ip = get_ip()
set_dns(ip, args.user, args.password)
except KeyboardInterrupt:
os._exit(1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment