ip / app.py
seawolf2357's picture
Create app.py
0837ea6 verified
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()