DmitrMakeev commited on
Commit
25028e8
·
verified ·
1 Parent(s): 115e1c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py CHANGED
@@ -229,6 +229,36 @@ def index_set():
229
 
230
 
231
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
 
233
 
234
 
 
229
 
230
 
231
 
232
+ def get_ip_address():
233
+ # Создаем сокет для получения IP-адреса
234
+ temp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
235
+ try:
236
+ # Подключаемся к публичному серверу
237
+ temp_socket.connect(("8.8.8.8", 80))
238
+ ip_address = temp_socket.getsockname()[0]
239
+ finally:
240
+ temp_socket.close()
241
+ return ip_address
242
+
243
+ @app.route('/ip')
244
+ def index():
245
+ # Получаем IP-адрес и порт
246
+ ip_address = get_ip_address()
247
+ port = 5000 # Порт по умолчанию для Flask
248
+ # Формируем HTML-страницу
249
+ html = f"""
250
+ <html>
251
+ <head>
252
+ <title>Server Info</title>
253
+ </head>
254
+ <body>
255
+ <h1>Server Information</h1>
256
+ <p>IP Address: {ip_address}</p>
257
+ <p>Port: {port}</p>
258
+ </body>
259
+ </html>
260
+ """
261
+ return render_template_string(html)
262
 
263
 
264