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指令,获取返回值
作者:黄海
func RunShell(c string) (string, error) {
cmd := exec.Command("sh", "-c", c)
out, err := cmd.Output()
return string(out), err