判断端口是否可以(未被占用)
(port int)
| 100 | |
| 101 | // 判断端口是否可以(未被占用) |
| 102 | func (instance *SSHRemote) IsPortAvailable(port int) bool { |
| 103 | command := fmt.Sprintf("sudo ss -tulwn | grep :%v", port) |
| 104 | output, err := instance.ExeSSHCommand(command) |
| 105 | if err != nil { |
| 106 | if output != "" || err.Error() != "Process exited with status 1" { |
| 107 | SmartIDELog.Error(err, output) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return !strings.Contains(output, ":"+strconv.Itoa(port)) |
| 112 | } |
| 113 | |
| 114 | // 检查当前端口是否被占用,并返回一个可用端口 |
| 115 | func (instance *SSHRemote) CheckAndGetAvailableRemotePort(checkPort int, step int) (usablePort int) { |
no test coverage detected