Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests, socket, json | |
| def get_server_ips(request: gr.Request): | |
| # ํผ๋ธ๋ฆญ IP | |
| public_ip = "์ ์ ์์" | |
| try: | |
| public_ip = requests.get("https://api.ipify.org", timeout=5).text.strip() | |
| except Exception as e: | |
| public_ip = f"์กฐํ ์คํจ: {e}" | |
| # ํ๋ผ์ด๋น IP | |
| private_ip = "์ ์ ์์" | |
| try: | |
| hostname = socket.gethostname() | |
| private_ip = socket.gethostbyname(hostname) | |
| except Exception as e: | |
| private_ip = f"์กฐํ ์คํจ: {e}" | |
| info = { | |
| "public_ip": public_ip, | |
| "private_ip": private_ip, | |
| } | |
| # ๋ณด๊ธฐ ์ข๊ฒ JSON ๋ฌธ์์ด๋ก ๋ฐํ | |
| return json.dumps(info, ensure_ascii=False, indent=2) | |
| with gr.Blocks(title="Server IP Checker") as demo: | |
| gr.Markdown("# ์๋ฒ IP ์กฐํ") | |
| btn = gr.Button("์๋ฒ IP ํ์ธ") | |
| out = gr.Code(label="๊ฒฐ๊ณผ(JSON)", language="json") | |
| btn.click(fn=get_server_ips, inputs=None, outputs=out) | |
| if __name__ == "__main__": | |
| demo.launch() | |