Skip to content

Commit

Permalink
refactor: IP주소 실시간으로 불러오기
Browse files Browse the repository at this point in the history
  • Loading branch information
kooqooo committed Aug 8, 2024
1 parent 261eb55 commit 2ff330c
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import os
import yaml
import socket
import requests


def get_public_ip():
response = requests.get('https://checkip.amazonaws.com')
public_ip = response.text.strip()
return public_ip

def get_private_ip():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
private_ip = s.getsockname()[0]
s.close()
except Exception as e:
hostname = socket.gethostname()
private_ip = socket.gethostbyname(hostname)
return private_ip


path = os.getcwd() # 상위 폴더에서 실행된 경우 -> secret_key.yaml이 상위 폴더에 있음
# path = os.path.dirname(os.path.abspath(__file__)) # 현재 폴더에서 실행된 경우 -> secret_key.yaml이 현재 폴더에 있음
Expand All @@ -10,8 +30,8 @@
OPENAI_API_KEY = cfg["OPENAI_API_KEY"]
COHERE_API_KEY = cfg["COHERE_API_KEY"]

INSIDE_IP = cfg["IP"]["INSIDE_IP"]
OUTSIDE_IP = cfg["IP"]["OUTSIDE_IP"]
INSIDE_IP = get_private_ip()
OUTSIDE_IP = get_public_ip()

REST_API_KEY = cfg["Kakaologin"]["REST_API_KEY"]
REDIRECT_URI = f"http://{OUTSIDE_IP}:{cfg['PORT']}/auth"
Expand Down

0 comments on commit 2ff330c

Please sign in to comment.