From 09e4c7c6e796238464f463d30dd332b0c4723343 Mon Sep 17 00:00:00 2001 From: drmext <71258889+drmext@users.noreply.github.com> Date: Mon, 5 Sep 2022 23:40:46 +0000 Subject: [PATCH] Get local IP automatically --- config.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 2859206..dbf5064 100644 --- a/config.py +++ b/config.py @@ -1,4 +1,19 @@ -ip = '127.0.0.1' +import socket + +# https://stackoverflow.com/a/28950776 +def get_ip(): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.settimeout(0) + try: + s.connect(('10.254.254.254', 1)) + IP = s.getsockname()[0] + except Exception: + IP = '127.0.0.1' + finally: + s.close() + return IP + +ip = get_ip() port = 8000 services_prefix = "/core" verbose_log = True