aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gandi_dns_update.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/gandi_dns_update.py b/gandi_dns_update.py
index 6bce6fb..af3e7af 100644
--- a/gandi_dns_update.py
+++ b/gandi_dns_update.py
@@ -18,13 +18,25 @@ import http.client
logger = logging.getLogger(__name__)
+class IPv4HTTPSConnection(http.client.HTTPSConnection):
+ """"""
+ def connect(self):
+ """"""
+ self.sock = socket.socket(socket.AF_INET)
+ self.sock.connect((self.host, int(self.port)))
+ if self._tunnel_host:
+ self._tunnel()
+ self.sock = self._context.wrap_socket(self.sock,
+ server_hostname=self.host)
+
+
def get_ip_from_ifconfig_me(
) -> typing.Tuple[bool, typing.Optional[bytes]]:
""""""
- conn = http.client.HTTPSConnection('ifconfig.me') # nosec
+ conn = IPv4HTTPSConnection('ifconfig.me') # nosec
try:
- conn.request('GET', '/')
+ conn.request('GET', '/ip')
r = conn.getresponse()
data = r.read()
r.close()
@@ -43,7 +55,7 @@ def get_ip_from_ifconfig_me(
def get_ip_from_ipecho_net(
) -> typing.Tuple[bool, typing.Optional[bytes]]:
""""""
- conn = http.client.HTTPSConnection('ipecho.net') # nosec
+ conn = IPv4HTTPSConnection('ipecho.net') # nosec
try:
conn.request('GET', '/plain')
@@ -65,7 +77,7 @@ def get_ip_from_ipecho_net(
def get_ip_from_ipinfo_io(
) -> typing.Tuple[bool, typing.Optional[bytes]]:
""""""
- conn = http.client.HTTPSConnection('ipinfo.io') # nosec
+ conn = IPv4HTTPSConnection('ipinfo.io') # nosec
try:
conn.request('GET', '/ip')
r = conn.getresponse()
@@ -123,7 +135,7 @@ if '__main__' == __name__:
handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
main_logger.addHandler(handler)
- main_logger.setLevel(logging.DEBUG)
+ main_logger.setLevel(logging.WARNING)
parser = argparse.ArgumentParser()
parser.add_argument('config_path', type=str)
@@ -157,6 +169,7 @@ if '__main__' == __name__:
ip_checks = [_ for _ in ip_addresses if _ == ip_addresses[0]]
if len(ip_checks) < len(ip_addresses):
logger.error('Public IP addresses do not match')
+ print(ip_checks)
sys.exit(1)
ip = ip_addresses[0]