MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / IsPortAvailable

Method IsPortAvailable

cli/pkg/common/sshremote.go:102–112  ·  view source on GitHub ↗

判断端口是否可以(未被占用)

(port int)

Source from the content-addressed store, hash-verified

100
101// 判断端口是否可以(未被占用)
102func (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// 检查当前端口是否被占用,并返回一个可用端口
115func (instance *SSHRemote) CheckAndGetAvailableRemotePort(checkPort int, step int) (usablePort int) {

Callers 1

Calls 2

ExeSSHCommandMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected