You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
664 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package CheckUtil
import (
"net"
"os/exec"
"strconv"
"time"
)
/**
功能:检查端口是汪是可以使用
作者:黄海
时间2020-04-11
*/
func PortInUse(host string, port int) bool {
timeout := time.Millisecond * 20
conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, strconv.Itoa(port)), timeout)
var isUse bool
if err != nil {
isUse = false
}
if conn != nil {
defer conn.Close()
isUse = true
}
return isUse
}
/**
功能运行Shell指令获取返回值
作者:黄海
时间2020-04-11
*/
func RunShell(c string) (string, error) {
cmd := exec.Command("sh", "-c", c)
out, err := cmd.Output()
return string(out), err
}