websoft9/appmanage/api/utils/network.py

16 lines
480 B
Python
Raw Normal View History

2023-02-22 09:14:44 +08:00
import os, io, sys, platform, shutil, time, json, datetime
2023-02-22 17:18:52 +08:00
from api.utils import shell_execute
2023-02-22 09:14:44 +08:00
2023-02-23 12:10:07 +08:00
# 根据.env文件提供的port找出能正常启动的最小port
2023-02-22 09:14:44 +08:00
def get_start_port(port):
2023-02-22 17:18:52 +08:00
use_port = port
while True:
2023-02-23 16:19:55 +08:00
cmd = "netstat -ntlp | grep -v only"
output = shell_execute.execute_command_output_all(cmd)
if output["result"].find(use_port)==-1:
2023-02-22 17:18:52 +08:00
break
else:
2023-02-23 16:19:55 +08:00
use_port = str(int(use_port)+1)
2023-02-22 09:14:44 +08:00
return use_port