seawolf2357 commited on
Commit
0837ea6
ยท
verified ยท
1 Parent(s): 628dc43

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests, socket, json
3
+
4
+ def get_server_ips(request: gr.Request):
5
+ # ํผ๋ธ”๋ฆญ IP
6
+ public_ip = "์•Œ ์ˆ˜ ์—†์Œ"
7
+ try:
8
+ public_ip = requests.get("https://api.ipify.org", timeout=5).text.strip()
9
+ except Exception as e:
10
+ public_ip = f"์กฐํšŒ ์‹คํŒจ: {e}"
11
+
12
+ # ํ”„๋ผ์ด๋น— IP
13
+ private_ip = "์•Œ ์ˆ˜ ์—†์Œ"
14
+ try:
15
+ hostname = socket.gethostname()
16
+ private_ip = socket.gethostbyname(hostname)
17
+ except Exception as e:
18
+ private_ip = f"์กฐํšŒ ์‹คํŒจ: {e}"
19
+
20
+ info = {
21
+ "public_ip": public_ip,
22
+ "private_ip": private_ip,
23
+ }
24
+ # ๋ณด๊ธฐ ์ข‹๊ฒŒ JSON ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜
25
+ return json.dumps(info, ensure_ascii=False, indent=2)
26
+
27
+ with gr.Blocks(title="Server IP Checker") as demo:
28
+ gr.Markdown("# ์„œ๋ฒ„ IP ์กฐํšŒ")
29
+ btn = gr.Button("์„œ๋ฒ„ IP ํ™•์ธ")
30
+ out = gr.Code(label="๊ฒฐ๊ณผ(JSON)", language="json")
31
+ btn.click(fn=get_server_ips, inputs=None, outputs=out)
32
+
33
+ if __name__ == "__main__":
34
+ demo.launch()