Newer
Older
certbot-dns-inwx / getIPaddress.py
#!/usr/bin/env python3
# -*- encoding: UTF8 -*-

# author: Pascal Gollor (https://gitbucket.pgollor.de)


import argparse
import requests

def getPublicIP(ipv4=False, verbose=False):
	ipstr = '6'
	if (ipv4):
		ipstr = '4'
	r = requests.get('http://v' + ipstr + '.pgollor.de/ip.php?raw')
	if (not r.ok):
		raise RuntimeError()
	
	ip = r.text
	if (verbose):
		print('ip:', ip)
	
	return ip
# end getPublicIP


if __name__ == '__main__':
	parser = argparse.ArgumentParser(description='inwx subdomain update')
	parser.add_argument('ipv', metavar='ip type', choices=['4', '6'], help='4: IPv4, 6: IPv6')
	parser.add_argument('-v', '--verbose', action='store_true', help='verbose')
	args = parser.parse_args()
	
	ipv = int(args.ipv)
	
	try:
		getPublicIP(ipv4=ipv==4, verbose=args.verbose)
	except RuntimeError as e:
		print('[ERROR]:', e)
	# end try
# end if