Files
docker_minecraft_server_aut…/app/utils.py
2023-12-10 22:01:37 +01:00

25 lines
642 B
Python

import logging
import os
import socket
import socket
def docker_container_mapping():
port_ip_map_str = os.environ.get('PORT_MAP')
# Convert the environment variable to a Python dictionary
port_ip_map = {}
for line in port_ip_map_str.split('\n'):
if line: # ignore empty lines
port, ip = line.split(':')
port_ip_map[port.strip()] = ip.strip()
return port_ip_map
def get_ip_by_dns_name(dns_name):
try:
return socket.gethostbyname(dns_name, resolver='127.0.0.1')
except socket.gaierror:
logging.error(f'Could not resolve dns name {dns_name}')
return None